Get max sets for each workout in plan

Closes #91
This commit is contained in:
Brandon Presley 2022-10-16 16:08:38 +13:00
parent 7bd2254719
commit f078ede58a
3 changed files with 13 additions and 11 deletions

View File

@ -30,7 +30,7 @@ export default function StartPlan() {
const {toast} = useSnackbar(); const {toast} = useSnackbar();
const [minutes, setMinutes] = useState(set.minutes); const [minutes, setMinutes] = useState(set.minutes);
const [seconds, setSeconds] = useState(set.seconds); const [seconds, setSeconds] = useState(set.seconds);
const [best, setBest] = useState<Set>(); const [best, setBest] = useState<Set>(set);
const [selected, setSelected] = useState(0); const [selected, setSelected] = useState(0);
const {settings} = useSettings(); const {settings} = useSettings();
const [counts, setCounts] = useState<CountMany[]>(); const [counts, setCounts] = useState<CountMany[]>();
@ -56,8 +56,7 @@ export default function StartPlan() {
title: params.plan.days.replace(/,/g, ', '), title: params.plan.days.replace(/,/g, ', '),
}); });
countManyToday().then(setCounts); countManyToday().then(setCounts);
getBestSet(workouts[0]).then(setBest); }, [navigation, params]),
}, [navigation, params, workouts]),
); );
const handleSubmit = async () => { const handleSubmit = async () => {
@ -73,12 +72,11 @@ export default function StartPlan() {
unit, unit,
}); });
countManyToday().then(setCounts); countManyToday().then(setCounts);
if (!best) toast('Added set', 3000); if (
else if (
settings.notify && settings.notify &&
(+weight > best.weight || (+reps > best.reps && +weight === best.weight)) (+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 if (settings.alarm) toast('Resting...', 3000);
else toast('Added set', 3000); else toast('Added set', 3000);
if (!settings.alarm) return; if (!settings.alarm) return;
@ -114,9 +112,12 @@ export default function StartPlan() {
[name, workouts], [name, workouts],
); );
const getTotal = useCallback( const getDescription = useCallback(
(countName: string) => (countName: string) => {
counts?.find(count => count.name === countName)?.total || 0, const count = counts?.find(c => c.name === countName);
if (!count) return;
return `${count.total} / ${count.sets}`;
},
[counts], [counts],
); );
@ -156,7 +157,7 @@ export default function StartPlan() {
renderItem={({item, index}) => ( renderItem={({item, index}) => (
<List.Item <List.Item
title={item} title={item}
description={getTotal(item) + `/${set.sets}`} description={getDescription(item)}
onPress={() => select(index)} onPress={() => select(index)}
left={() => ( left={() => (
<View style={{alignItems: 'center', justifyContent: 'center'}}> <View style={{alignItems: 'center', justifyContent: 'center'}}>

View File

@ -1,4 +1,5 @@
export default interface CountMany { export default interface CountMany {
name: string; name: string;
total: number; total: number;
sets: number;
} }

View File

@ -157,7 +157,7 @@ export const countToday = async (name: string): Promise<number> => {
export const countManyToday = async (): Promise<CountMany[]> => { export const countManyToday = async (): Promise<CountMany[]> => {
const select = ` 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') WHERE created LIKE strftime('%Y-%m-%d%%', 'now', 'localtime')
AND NOT hidden AND NOT hidden
GROUP BY name GROUP BY name