From ffbefe7a4fb58456a6251ad620a3d95753e3ad8a Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Wed, 2 Nov 2022 12:58:57 +1300 Subject: [PATCH] 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. --- PlanPage.tsx | 2 ++ StartPlanItem.tsx | 20 ++++++++++++++++++++ plan-page-params.ts | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/PlanPage.tsx b/PlanPage.tsx index 0507684..5dd4fc7 100644 --- a/PlanPage.tsx +++ b/PlanPage.tsx @@ -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() { + ) } diff --git a/StartPlanItem.tsx b/StartPlanItem.tsx index a4f4d6c..4b97e50 100644 --- a/StartPlanItem.tsx +++ b/StartPlanItem.tsx @@ -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 { @@ -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>() 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 ( setShowMenu(false)}> + diff --git a/plan-page-params.ts b/plan-page-params.ts index f336b1d..cf4b2e8 100644 --- a/plan-page-params.ts +++ b/plan-page-params.ts @@ -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 + } }