Auto select last worked on exercise in plans

This commit is contained in:
Brandon Presley 2024-02-09 14:24:59 +13:00
parent cf90b798ab
commit 6ea65bcd16
1 changed files with 5 additions and 1 deletions

View File

@ -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<string>(params.first?.unit || "kg");
const [selected, setSelected] = useState(0);
const [selected, setSelected] = useState<number | null>(null);
const [settings, setSettings] = useState<Settings>();
const [counts, setCounts] = useState<CountMany[]>();
const weightRef = useRef<TextInput>(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
}, [])
);