Simplify set prediction by returning early

This commit is contained in:
Brandon Presley 2022-09-28 14:06:51 +13:00
parent cdb4ceec28
commit 64d046fe8f

View File

@ -36,13 +36,13 @@ export default function SetList() {
if (!settings.predict) return; if (!settings.predict) return;
const todaysPlan = await getTodaysPlan(); const todaysPlan = await getTodaysPlan();
if (todaysPlan.length === 0) return; if (todaysPlan.length === 0) return;
const todaysSet = await getToday();
const todaysWorkouts = todaysPlan[0].workouts.split(','); const todaysWorkouts = todaysPlan[0].workouts.split(',');
setWorkouts(todaysWorkouts); setWorkouts(todaysWorkouts);
let workout = todaysWorkouts[0]; let workout = todaysWorkouts[0];
let best = await getBestSet(workout); let best = await getBestSet(workout);
console.log({todaysSet, todaysWorkouts, todaysPlan}); const todaysSet = await getToday();
if (todaysSet && todaysWorkouts.includes(todaysSet.name)) { if (!todaysSet || !todaysWorkouts.includes(todaysSet.name))
return setSet(best);
let _count = await countToday(todaysSet.name); let _count = await countToday(todaysSet.name);
workout = todaysSet.name; workout = todaysSet.name;
best = await getBestSet(workout); best = await getBestSet(workout);
@ -53,9 +53,7 @@ export default function SetList() {
} }
if (best.name === '') setCount(0); if (best.name === '') setCount(0);
else setCount(_count); else setCount(_count);
} setSet(best);
console.log({best});
setSet({...best});
}, []); }, []);
const refresh = useCallback(async () => { const refresh = useCallback(async () => {