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