feat: list exercise history by day
This commit is contained in:
parent
1980017210
commit
ea7341f26e
3 changed files with 17 additions and 4 deletions
6
src/dtos/HistoryByDayDTO.ts
Normal file
6
src/dtos/HistoryByDayDTO.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import { HistoryDTO } from './HistoryDTO';
|
||||||
|
|
||||||
|
export type HistoryByDayDTO = {
|
||||||
|
title: string;
|
||||||
|
data: HistoryDTO[];
|
||||||
|
};
|
||||||
7
src/dtos/HistoryDTO.ts
Normal file
7
src/dtos/HistoryDTO.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
export type HistoryDTO = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
group: string;
|
||||||
|
hour: number;
|
||||||
|
created_at: string;
|
||||||
|
};
|
||||||
|
|
@ -5,7 +5,7 @@ import { Heading, Text, useToast, VStack } from '@gluestack-ui/themed';
|
||||||
|
|
||||||
import { api } from '@services/api';
|
import { api } from '@services/api';
|
||||||
import { AppError } from '@utils/AppError';
|
import { AppError } from '@utils/AppError';
|
||||||
import { ExerciseDTO } from '@dtos/ExerciseDTO';
|
import { HistoryByDayDTO } from '@dtos/HistoryByDayDTO';
|
||||||
|
|
||||||
import { HistoryCard } from '@components/HistoryCard';
|
import { HistoryCard } from '@components/HistoryCard';
|
||||||
import { ScreenHeader } from '@components/ScreenHeader';
|
import { ScreenHeader } from '@components/ScreenHeader';
|
||||||
|
|
@ -13,7 +13,7 @@ import { ToastMessage } from '@components/ToastMessage';
|
||||||
|
|
||||||
export function History() {
|
export function History() {
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [exercises, setExercises] = useState<ExerciseDTO[]>([]);
|
const [exercises, setExercises] = useState<HistoryByDayDTO[]>([]);
|
||||||
|
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ export function History() {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
const response = await api.get('/history');
|
const response = await api.get('/history');
|
||||||
console.debug(response.data);
|
setExercises(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const isAppError = error instanceof AppError;
|
const isAppError = error instanceof AppError;
|
||||||
const title = isAppError ? error.message : 'Não foi possível carregar o histórico.';
|
const title = isAppError ? error.message : 'Não foi possível carregar o histórico.';
|
||||||
|
|
@ -49,7 +49,7 @@ export function History() {
|
||||||
|
|
||||||
<SectionList
|
<SectionList
|
||||||
sections={exercises}
|
sections={exercises}
|
||||||
keyExtractor={(item) => item}
|
keyExtractor={(item) => item.id}
|
||||||
renderItem={({ item }) => <HistoryCard data={item} />}
|
renderItem={({ item }) => <HistoryCard data={item} />}
|
||||||
renderSectionHeader={({ section }) => (
|
renderSectionHeader={({ section }) => (
|
||||||
<Heading color="$gray200" fontSize="$md" mt="$10" mb="$3">
|
<Heading color="$gray200" fontSize="$md" mt="$10" mb="$3">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue