Save plan before starting it

Also after saving it makes more sense to just
navigate to PlanList instead of calling
navigation.goBack(). This way we can make sure
we have up-to-date data.

The old way would typically lead to us seeing
stale data. E.g.
1. Tap on a plan
2. Tap on edit
3. Change details of the plan
4. Press save
5. See old plan

Now when we save we instead see the original list of plans.
This commit is contained in:
Brandon Presley 2023-07-31 15:54:32 +12:00
parent 158dd61668
commit 95681c0b3d
1 changed files with 8 additions and 4 deletions

View File

@ -46,8 +46,7 @@ export default function EditPlan() {
const newWorkouts = workouts.filter((workout) => workout).join(',')
const newDays = days.filter((day) => day).join(',')
await planRepo.save({ days: newDays, workouts: newWorkouts, id: plan.id })
navigation.goBack()
}, [days, workouts, plan, navigation])
}, [days, workouts, plan])
const toggleWorkout = useCallback(
(on: boolean, name: string) => {
@ -79,13 +78,15 @@ export default function EditPlan() {
{typeof plan.id === 'number' && (
<IconButton
onPress={async () => {
await save()
const newPlan = await planRepo.findOne({ where: { id: plan.id } })
let first = await setRepo.findOne({
where: { name: workouts[0] },
order: { created: 'desc' },
})
if (!first) first = { ...defaultSet, name: workouts[0] }
delete first.id
navigation.navigate('StartPlan', { plan: params.plan, first })
navigation.navigate('StartPlan', { plan: newPlan, first })
}}
icon='play-arrow'
/>
@ -126,7 +127,10 @@ export default function EditPlan() {
style={styles.button}
mode='outlined'
icon='save'
onPress={save}
onPress={async () => {
await save()
navigation.navigate('PlanList')
}}
>
Save
</Button>