From f078ede58a844f3741f36c85372cff3b2d5f00e6 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Sun, 16 Oct 2022 16:08:38 +1300 Subject: [PATCH] Get max sets for each workout in plan Closes #91 --- StartPlan.tsx | 21 +++++++++++---------- count-many.ts | 1 + set.service.ts | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/StartPlan.tsx b/StartPlan.tsx index ad9558b..706929e 100644 --- a/StartPlan.tsx +++ b/StartPlan.tsx @@ -30,7 +30,7 @@ export default function StartPlan() { const {toast} = useSnackbar(); const [minutes, setMinutes] = useState(set.minutes); const [seconds, setSeconds] = useState(set.seconds); - const [best, setBest] = useState(); + const [best, setBest] = useState(set); const [selected, setSelected] = useState(0); const {settings} = useSettings(); const [counts, setCounts] = useState(); @@ -56,8 +56,7 @@ export default function StartPlan() { title: params.plan.days.replace(/,/g, ', '), }); countManyToday().then(setCounts); - getBestSet(workouts[0]).then(setBest); - }, [navigation, params, workouts]), + }, [navigation, params]), ); const handleSubmit = async () => { @@ -73,12 +72,11 @@ export default function StartPlan() { unit, }); countManyToday().then(setCounts); - if (!best) toast('Added set', 3000); - else if ( + if ( settings.notify && (+weight > best.weight || (+reps > best.reps && +weight === best.weight)) ) - toast("Great work King! That's a new record.", 3000); + toast("Great work King! That's a new record.", 5000); else if (settings.alarm) toast('Resting...', 3000); else toast('Added set', 3000); if (!settings.alarm) return; @@ -114,9 +112,12 @@ export default function StartPlan() { [name, workouts], ); - const getTotal = useCallback( - (countName: string) => - counts?.find(count => count.name === countName)?.total || 0, + const getDescription = useCallback( + (countName: string) => { + const count = counts?.find(c => c.name === countName); + if (!count) return; + return `${count.total} / ${count.sets}`; + }, [counts], ); @@ -156,7 +157,7 @@ export default function StartPlan() { renderItem={({item, index}) => ( select(index)} left={() => ( diff --git a/count-many.ts b/count-many.ts index d97c39a..7d10775 100644 --- a/count-many.ts +++ b/count-many.ts @@ -1,4 +1,5 @@ export default interface CountMany { name: string; total: number; + sets: number; } diff --git a/set.service.ts b/set.service.ts index 2114e08..c3d80dc 100644 --- a/set.service.ts +++ b/set.service.ts @@ -157,7 +157,7 @@ export const countToday = async (name: string): Promise => { export const countManyToday = async (): Promise => { const select = ` - SELECT COUNT(*) as total, name FROM sets + SELECT COUNT(*) as total, name, sets FROM sets WHERE created LIKE strftime('%Y-%m-%d%%', 'now', 'localtime') AND NOT hidden GROUP BY name