diff --git a/src/screens/Home.tsx b/src/screens/Home.tsx index 5711c8b..045158b 100644 --- a/src/screens/Home.tsx +++ b/src/screens/Home.tsx @@ -13,8 +13,10 @@ import { ExerciseCard } from '@components/ExerciseCard'; import { Group } from '@components/Group'; import { HomeHeader } from '@components/HomeHeader'; import { ToastMessage } from '@components/ToastMessage'; +import { Loading } from '@components/Loading'; export function Home() { + const [isLoading, setIsLoading] = useState(true); const [exercises, setExercises] = useState([]); const [groups, setGroups] = useState([]); const [selectedGroup, setSelectedGroup] = useState('costas'); @@ -44,6 +46,7 @@ export function Home() { async function fetchExercisesForGroup(group: string) { try { + setIsLoading(true); const response = await api.get(`/exercises/bygroup/${selectedGroup}`); setExercises(response.data); } catch (error) { @@ -55,6 +58,8 @@ export function Home() { toast.close(id)} /> ), }); + } finally { + setIsLoading(false); } } @@ -92,27 +97,31 @@ export function Home() { }} /> - - - - ExercĂ­cios - + {isLoading ? ( + + ) : ( + + + + ExercĂ­cios + - - 4 - - + + 4 + + - item.id} - renderItem={({ item }) => ( - - )} - showsVerticalScrollIndicator={false} - contentContainerStyle={{ paddingBottom: 20 }} - /> - + item.id} + renderItem={({ item }) => ( + + )} + showsVerticalScrollIndicator={false} + contentContainerStyle={{ paddingBottom: 20 }} + /> + + )} ); }