From 6ea65bcd164d4bc7d6ab6e698db83d0c5755e44e Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Fri, 9 Feb 2024 14:24:59 +1300 Subject: [PATCH] Auto select last worked on exercise in plans --- StartPlan.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/StartPlan.tsx b/StartPlan.tsx index 94fef5b..88a1cbe 100644 --- a/StartPlan.tsx +++ b/StartPlan.tsx @@ -31,7 +31,7 @@ export default function StartPlan() { const [reps, setReps] = useState(params.first?.reps.toString() || "0"); const [weight, setWeight] = useState(params.first?.weight.toString() || "0"); const [unit, setUnit] = useState(params.first?.unit || "kg"); - const [selected, setSelected] = useState(0); + const [selected, setSelected] = useState(null); const [settings, setSettings] = useState(); const [counts, setCounts] = useState(); const weightRef = useRef(null); @@ -88,6 +88,10 @@ export default function StartPlan() { useCallback(() => { settingsRepo.findOne({ where: {} }).then(setSettings); refresh(); + setRepo.find({ order: { created: "DESC" }, take: 1 }).then(sets => { + const index = exercises.findIndex(exercise => exercise === sets[0].name); + setSelected(index === -1 ? 0 : index); + }); // eslint-disable-next-line }, []) );