wip
This commit is contained in:
parent
4e8ec92c27
commit
2902b317b6
2 changed files with 38 additions and 1 deletions
|
|
@ -21,7 +21,9 @@ type RouteParams = {
|
|||
};
|
||||
|
||||
export function Exercise() {
|
||||
const [sendingExerciseRegister, setSendingExerciseRegister] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const [exercise, setExercise] = useState<ExerciseDTO>({} 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 }) => (
|
||||
<ToastMessage
|
||||
id={id}
|
||||
title="Parabéns! Exercício registrado no seu hitórico."
|
||||
action="success"
|
||||
onClose={() => 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 }) => (
|
||||
<ToastMessage id={id} title={title} action="error" onClose={() => toast.close(id)} />
|
||||
),
|
||||
});
|
||||
} finally {
|
||||
setSendingExerciseRegister(false);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetchExerciseData();
|
||||
|
|
@ -114,7 +146,11 @@ export function Exercise() {
|
|||
</HStack>
|
||||
</HStack>
|
||||
|
||||
<Button title="Marcar como realizado" />
|
||||
<Button
|
||||
title="Marcar como realizado"
|
||||
isLoading={sendingExerciseRegister}
|
||||
onPress={handleExerciseHistoryRegister}
|
||||
/>
|
||||
</Box>
|
||||
</VStack>
|
||||
</ScrollView>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import { Loading } from '@components/Loading';
|
|||
|
||||
export function Home() {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const [exercises, setExercises] = useState<ExerciseDTO[]>([]);
|
||||
const [groups, setGroups] = useState<string[]>([]);
|
||||
const [selectedGroup, setSelectedGroup] = useState('antebraço');
|
||||
|
|
|
|||
Loading…
Reference in a new issue