From 374cbdf45da0f475161f8c9cb14f0b74de6d1e78 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Thu, 29 Sep 2022 14:44:01 +1300 Subject: [PATCH] Add set prediction settings Closes #51 --- SetList.tsx | 5 +++-- SettingsPage.tsx | 31 +++++++++++++++++-------------- db.ts | 3 +++ settings.ts | 2 +- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/SetList.tsx b/SetList.tsx index 25737a1..da50094 100644 --- a/SetList.tsx +++ b/SetList.tsx @@ -33,14 +33,15 @@ export default function SetList() { const predict = useCallback(async () => { setCount(0); setSet({...defaultSet}); - if (!settings.predict) return; + if (settings.newSet === 'empty') return; + const todaysSet = await getToday(); + if (!settings.newSet && todaysSet) return setSet({...todaysSet}); const todaysPlan = await getTodaysPlan(); if (todaysPlan.length === 0) return; const todaysWorkouts = todaysPlan[0].workouts.split(','); setWorkouts(todaysWorkouts); let workout = todaysWorkouts[0]; let best = await getBestSet(workout); - const todaysSet = await getToday(); if (!todaysSet || !todaysWorkouts.includes(todaysSet.name)) return setSet(best); let _count = await countToday(todaysSet.name); diff --git a/SettingsPage.tsx b/SettingsPage.tsx index 5a8437b..95c5403 100644 --- a/SettingsPage.tsx +++ b/SettingsPage.tsx @@ -20,7 +20,7 @@ export default function SettingsPage() { const [search, setSearch] = useState(''); const [vibrate, setVibrate] = useState(!!settings.vibrate); const [alarm, setAlarm] = useState(!!settings.alarm); - const [predict, setPredict] = useState(!!settings.predict); + const [newSet, setNewSet] = useState(settings.newSet); const [sound, setSound] = useState(settings.sound); const [notify, setNotify] = useState(!!settings.notify); const [images, setImages] = useState(!!settings.images); @@ -40,7 +40,7 @@ export default function SettingsPage() { updateSettings({ vibrate: +vibrate, alarm: +alarm, - predict: +predict, + newSet, sound, notify: +notify, images: +images, @@ -53,7 +53,7 @@ export default function SettingsPage() { }, [ vibrate, alarm, - predict, + newSet, sound, notify, images, @@ -73,15 +73,6 @@ export default function SettingsPage() { [setBattery, ignoring, toast], ); - const changePredict = useCallback( - (enabled: boolean) => { - setPredict(enabled); - if (enabled) toast('Predict your next set based on todays plan.', 4000); - else toast('New sets will always be empty.', 4000); - }, - [setPredict, toast], - ); - const changeVibrate = useCallback( (enabled: boolean) => { setVibrate(enabled); @@ -149,7 +140,6 @@ export default function SettingsPage() { const switches: Input[] = [ {name: 'Rest timers', value: alarm, onChange: changeAlarmEnabled}, {name: 'Vibrate', value: vibrate, onChange: changeVibrate}, - {name: 'Predict sets', value: predict, onChange: changePredict}, {name: 'Record notifications', value: notify, onChange: changeNotify}, {name: 'Show images', value: images, onChange: changeImages}, {name: 'Show unit', value: showUnit, onChange: changeUnit}, @@ -173,6 +163,17 @@ export default function SettingsPage() { {input.name} ))} + {'new set'.includes(search.toLowerCase()) && ( + setNewSet(value)}> + + + + + )} {'theme'.includes(search.toLowerCase()) && ( )} {'alarm sound'.includes(search.toLowerCase()) && ( -