feat: fetch exercises for selected group
This commit is contained in:
parent
d1ecea5c0a
commit
0a4f91c1e0
1 changed files with 29 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { FlatList } from 'react-native';
|
import { FlatList } from 'react-native';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useFocusEffect, useNavigation } from '@react-navigation/native';
|
||||||
import { Heading, HStack, Text, useToast, VStack } from '@gluestack-ui/themed';
|
import { Heading, HStack, Text, useToast, VStack } from '@gluestack-ui/themed';
|
||||||
|
|
||||||
import { AppNavigatorRoutesProps } from '@routes/app.routes';
|
import { AppNavigatorRoutesProps } from '@routes/app.routes';
|
||||||
|
|
@ -31,10 +31,29 @@ export function Home() {
|
||||||
setGroups(response.data);
|
setGroups(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 os grupos musculares';
|
const title = isAppError ? error.message : 'Não foi possível carregar os grupos musculares.';
|
||||||
toast.show({
|
toast.show({
|
||||||
placement: 'top',
|
placement: 'top',
|
||||||
render: ({ id }) => <ToastMessage id={id} title={title} onClose={() => toast.close(id)} />,
|
render: ({ id }) => (
|
||||||
|
<ToastMessage id={id} title={title} action="error" onClose={() => toast.close(id)} />
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchExercisesForGroup(group: string) {
|
||||||
|
try {
|
||||||
|
const response = await api.get(`/exercises/bygroup/${selectedGroup}`);
|
||||||
|
console.debug(response.data);
|
||||||
|
// setGroups(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
const isAppError = error instanceof AppError;
|
||||||
|
const title = isAppError ? error.message : 'Não foi possível carregar os exercícios.';
|
||||||
|
toast.show({
|
||||||
|
placement: 'top',
|
||||||
|
render: ({ id }) => (
|
||||||
|
<ToastMessage id={id} title={title} action="error" onClose={() => toast.close(id)} />
|
||||||
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -43,6 +62,12 @@ export function Home() {
|
||||||
fetchGroups();
|
fetchGroups();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
fetchExercisesForGroup(selectedGroup);
|
||||||
|
}, [selectedGroup]),
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack flex={1}>
|
<VStack flex={1}>
|
||||||
<HomeHeader />
|
<HomeHeader />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue