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:
parent
0f6102f433
commit
ffbefe7a4f
|
@ -1,5 +1,6 @@
|
||||||
import {createStackNavigator} from '@react-navigation/stack'
|
import {createStackNavigator} from '@react-navigation/stack'
|
||||||
import EditPlan from './EditPlan'
|
import EditPlan from './EditPlan'
|
||||||
|
import EditSet from './EditSet'
|
||||||
import {PlanPageParams} from './plan-page-params'
|
import {PlanPageParams} from './plan-page-params'
|
||||||
import PlanList from './PlanList'
|
import PlanList from './PlanList'
|
||||||
import StartPlan from './StartPlan'
|
import StartPlan from './StartPlan'
|
||||||
|
@ -13,6 +14,7 @@ export default function PlanPage() {
|
||||||
<Stack.Screen name="PlanList" component={PlanList} />
|
<Stack.Screen name="PlanList" component={PlanList} />
|
||||||
<Stack.Screen name="EditPlan" component={EditPlan} />
|
<Stack.Screen name="EditPlan" component={EditPlan} />
|
||||||
<Stack.Screen name="StartPlan" component={StartPlan} />
|
<Stack.Screen name="StartPlan" component={StartPlan} />
|
||||||
|
<Stack.Screen name="EditSet" component={EditSet} />
|
||||||
</Stack.Navigator>
|
</Stack.Navigator>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
|
import {NavigationProp, useNavigation} from '@react-navigation/native'
|
||||||
import React, {useCallback, useState} from 'react'
|
import React, {useCallback, useState} from 'react'
|
||||||
import {GestureResponderEvent, ListRenderItemInfo, View} from 'react-native'
|
import {GestureResponderEvent, ListRenderItemInfo, View} from 'react-native'
|
||||||
import {List, Menu, RadioButton, useTheme} from 'react-native-paper'
|
import {List, Menu, RadioButton, useTheme} from 'react-native-paper'
|
||||||
import {Like} from 'typeorm'
|
import {Like} from 'typeorm'
|
||||||
import CountMany from './count-many'
|
import CountMany from './count-many'
|
||||||
import {getNow, setRepo} from './db'
|
import {getNow, setRepo} from './db'
|
||||||
|
import {PlanPageParams} from './plan-page-params'
|
||||||
import {toast} from './toast'
|
import {toast} from './toast'
|
||||||
|
|
||||||
interface Props extends ListRenderItemInfo<CountMany> {
|
interface Props extends ListRenderItemInfo<CountMany> {
|
||||||
|
@ -17,6 +19,7 @@ export default function StartPlanItem(props: Props) {
|
||||||
const {colors} = useTheme()
|
const {colors} = useTheme()
|
||||||
const [anchor, setAnchor] = useState({x: 0, y: 0})
|
const [anchor, setAnchor] = useState({x: 0, y: 0})
|
||||||
const [showMenu, setShowMenu] = useState(false)
|
const [showMenu, setShowMenu] = useState(false)
|
||||||
|
const {navigate} = useNavigation<NavigationProp<PlanPageParams>>()
|
||||||
|
|
||||||
const undo = useCallback(async () => {
|
const undo = useCallback(async () => {
|
||||||
const [{now}] = await getNow()
|
const [{now}] = await getNow()
|
||||||
|
@ -43,6 +46,22 @@ export default function StartPlanItem(props: Props) {
|
||||||
[setShowMenu, setAnchor],
|
[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 (
|
return (
|
||||||
<List.Item
|
<List.Item
|
||||||
onLongPress={longPress}
|
onLongPress={longPress}
|
||||||
|
@ -65,6 +84,7 @@ export default function StartPlanItem(props: Props) {
|
||||||
anchor={anchor}
|
anchor={anchor}
|
||||||
visible={showMenu}
|
visible={showMenu}
|
||||||
onDismiss={() => setShowMenu(false)}>
|
onDismiss={() => setShowMenu(false)}>
|
||||||
|
<Menu.Item icon="edit" onPress={edit} title="Edit" />
|
||||||
<Menu.Item icon="undo" onPress={undo} title="Undo" />
|
<Menu.Item icon="undo" onPress={undo} title="Undo" />
|
||||||
</Menu>
|
</Menu>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import GymSet from './gym-set'
|
||||||
import {Plan} from './plan'
|
import {Plan} from './plan'
|
||||||
|
|
||||||
export type PlanPageParams = {
|
export type PlanPageParams = {
|
||||||
|
@ -8,4 +9,7 @@ export type PlanPageParams = {
|
||||||
StartPlan: {
|
StartPlan: {
|
||||||
plan: Plan
|
plan: Plan
|
||||||
}
|
}
|
||||||
|
EditSet: {
|
||||||
|
set: GymSet
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user