diff --git a/src/screens/Exercise.tsx b/src/screens/Exercise.tsx index 20e7842..a8e8636 100644 --- a/src/screens/Exercise.tsx +++ b/src/screens/Exercise.tsx @@ -21,7 +21,9 @@ type RouteParams = { }; export function Exercise() { + const [sendingExerciseRegister, setSendingExerciseRegister] = useState(false); const [isLoading, setIsLoading] = useState(true); + const [exercise, setExercise] = useState({} as ExerciseDTO); const navigation = useNavigation(); @@ -54,6 +56,36 @@ export function Exercise() { setIsLoading(false); } } + async function handleExerciseHistoryRegister() { + try { + setSendingExerciseRegister(true); + + await api.post('/history', { exercise_id: exerciseId }); + + toast.show({ + placement: 'top', + render: ({ id }) => ( + toast.close(id)} + /> + ), + }); + } catch (error) { + const isAppError = error instanceof AppError; + const title = isAppError ? error.message : 'Não foi possível registrar o exercício.'; + toast.show({ + placement: 'top', + render: ({ id }) => ( + toast.close(id)} /> + ), + }); + } finally { + setSendingExerciseRegister(false); + } + } useEffect(() => { fetchExerciseData(); @@ -114,7 +146,11 @@ export function Exercise() { -