Add feature to edit last set from plan

If you are working through a plan, and accidentally
save an incorrect set (e.g. 100 reps instead of 10),
now you can long tap the item, and press edit. This
is slightly easier than swapping back over to the
home page to edit the set. Also since I reused the
same EditSet component this wasn't very much work.
This commit is contained in:
Brandon Presley 2022-11-02 12:58:57 +13:00
parent 0f6102f433
commit ffbefe7a4f
3 changed files with 26 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import {createStackNavigator} from '@react-navigation/stack'
import EditPlan from './EditPlan'
import EditSet from './EditSet'
import {PlanPageParams} from './plan-page-params'
import PlanList from './PlanList'
import StartPlan from './StartPlan'
@ -13,6 +14,7 @@ export default function PlanPage() {
<Stack.Screen name="PlanList" component={PlanList} />
<Stack.Screen name="EditPlan" component={EditPlan} />
<Stack.Screen name="StartPlan" component={StartPlan} />
<Stack.Screen name="EditSet" component={EditSet} />
</Stack.Navigator>
)
}

View File

@ -1,9 +1,11 @@
import {NavigationProp, useNavigation} from '@react-navigation/native'
import React, {useCallback, useState} from 'react'
import {GestureResponderEvent, ListRenderItemInfo, View} from 'react-native'
import {List, Menu, RadioButton, useTheme} from 'react-native-paper'
import {Like} from 'typeorm'
import CountMany from './count-many'
import {getNow, setRepo} from './db'
import {PlanPageParams} from './plan-page-params'
import {toast} from './toast'
interface Props extends ListRenderItemInfo<CountMany> {
@ -17,6 +19,7 @@ export default function StartPlanItem(props: Props) {
const {colors} = useTheme()
const [anchor, setAnchor] = useState({x: 0, y: 0})
const [showMenu, setShowMenu] = useState(false)
const {navigate} = useNavigation<NavigationProp<PlanPageParams>>()
const undo = useCallback(async () => {
const [{now}] = await getNow()
@ -43,6 +46,22 @@ export default function StartPlanItem(props: Props) {
[setShowMenu, setAnchor],
)
const edit = async () => {
const [{now}] = await getNow()
const created = now.split('T')[0]
const first = await setRepo.findOne({
where: {
name: item.name,
hidden: 0 as any,
created: Like(`${created}%`),
},
order: {created: 'desc'},
})
setShowMenu(false)
if (!first) return toast('Nothing to edit.')
navigate('EditSet', {set: first})
}
return (
<List.Item
onLongPress={longPress}
@ -65,6 +84,7 @@ export default function StartPlanItem(props: Props) {
anchor={anchor}
visible={showMenu}
onDismiss={() => setShowMenu(false)}>
<Menu.Item icon="edit" onPress={edit} title="Edit" />
<Menu.Item icon="undo" onPress={undo} title="Undo" />
</Menu>
</>

View File

@ -1,3 +1,4 @@
import GymSet from './gym-set'
import {Plan} from './plan'
export type PlanPageParams = {
@ -8,4 +9,7 @@ export type PlanPageParams = {
StartPlan: {
plan: Plan
}
EditSet: {
set: GymSet
}
}