From eddad497190a5cd0578514aa328f61f0008058e8 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Sun, 18 Sep 2022 18:15:58 +1200 Subject: [PATCH] Add button to remove image from a workout Closes #21 --- EditWorkout.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/EditWorkout.tsx b/EditWorkout.tsx index 594c2d6..98a8ec4 100644 --- a/EditWorkout.tsx +++ b/EditWorkout.tsx @@ -19,6 +19,7 @@ import {WorkoutsPageParams} from './WorkoutsPage'; export default function EditWorkout() { const [name, setName] = useState(''); + const [removeImage, setRemoveImage] = useState(false); const [steps, setSteps] = useState(''); const [uri, setUri] = useState(); const {params} = useRoute>(); @@ -52,10 +53,10 @@ export default function EditWorkout() { await updateSetName(params.value.name, name); await updateWorkouts(params.value.name, name); } - if (uri) await updateSetImage(params.value.name, uri); + if (uri || removeImage) await updateSetImage(params.value.name, uri || ''); if (steps) await updateSteps(params.value.name, steps); navigation.goBack(); - }, [navigation, params.value.name, name, uri, steps]); + }, [navigation, params.value.name, name, uri, steps, removeImage]); const add = useCallback(async () => { await addSet({name, reps: 0, weight: 0, hidden: true, image: uri} as Set); @@ -76,13 +77,21 @@ export default function EditWorkout() { if (fileCopyUri) setUri(fileCopyUri); }, []); + const onRemoveImage = useCallback(async () => { + setUri(''); + setRemoveImage(true); + }, []); + return ( {uri ? ( - - - + <> + + + + + ) : (