feat: list exercise history by day

This commit is contained in:
Vinicius Souza 2024-11-05 19:03:06 +00:00
parent 1980017210
commit ea7341f26e
3 changed files with 17 additions and 4 deletions

View file

@ -0,0 +1,6 @@
import { HistoryDTO } from './HistoryDTO';
export type HistoryByDayDTO = {
title: string;
data: HistoryDTO[];
};

7
src/dtos/HistoryDTO.ts Normal file
View file

@ -0,0 +1,7 @@
export type HistoryDTO = {
id: string;
name: string;
group: string;
hour: number;
created_at: string;
};

View file

@ -5,7 +5,7 @@ import { Heading, Text, useToast, VStack } from '@gluestack-ui/themed';
import { api } from '@services/api';
import { AppError } from '@utils/AppError';
import { ExerciseDTO } from '@dtos/ExerciseDTO';
import { HistoryByDayDTO } from '@dtos/HistoryByDayDTO';
import { HistoryCard } from '@components/HistoryCard';
import { ScreenHeader } from '@components/ScreenHeader';
@ -13,7 +13,7 @@ import { ToastMessage } from '@components/ToastMessage';
export function History() {
const [isLoading, setIsLoading] = useState(true);
const [exercises, setExercises] = useState<ExerciseDTO[]>([]);
const [exercises, setExercises] = useState<HistoryByDayDTO[]>([]);
const toast = useToast();
@ -22,7 +22,7 @@ export function History() {
setIsLoading(true);
const response = await api.get('/history');
console.debug(response.data);
setExercises(response.data);
} catch (error) {
const isAppError = error instanceof AppError;
const title = isAppError ? error.message : 'Não foi possível carregar o histórico.';
@ -49,7 +49,7 @@ export function History() {
<SectionList
sections={exercises}
keyExtractor={(item) => item}
keyExtractor={(item) => item.id}
renderItem={({ item }) => <HistoryCard data={item} />}
renderSectionHeader={({ section }) => (
<Heading color="$gray200" fontSize="$md" mt="$10" mb="$3">