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 + } }