Add toggle for predictive sets

This commit is contained in:
Brandon Presley 2022-07-10 17:53:38 +12:00
parent 5c65b283d3
commit 29d2421fb1
3 changed files with 24 additions and 0 deletions

View File

@ -49,6 +49,8 @@ const App = () => {
if (seconds === null) await setItem('seconds', '30');
const alarmEnabled = await getItem('alarmEnabled');
if (alarmEnabled === null) await setItem('alarmEnabled', 'false');
if (!(await getItem('predictiveSets')))
await setItem('predictiveSets', 'true');
};
init();
}, []);

View File

@ -150,6 +150,7 @@ export default function HomePage() {
const created = new Date().toISOString();
setNewSet({created});
setShowNew(true);
if ((await AsyncStorage.getItem('predictiveSets')) === 'false') return;
const todaysPlan = await getTodaysPlan();
if (todaysPlan.length === 0) return;
console.log(`${HomePage.name}.onAdd: todaysPlan =`, todaysPlan);

View File

@ -20,6 +20,7 @@ export default function SettingsPage() {
const [minutes, setMinutes] = useState<string>('');
const [seconds, setSeconds] = useState<string>('');
const [alarmEnabled, setAlarmEnabled] = useState<boolean>(false);
const [predictiveSets, setPredictiveSets] = useState<boolean>(false);
const [snackbar, setSnackbar] = useState('');
const [showBattery, setShowBattery] = useState(false);
const [ignoring, setIgnoring] = useState(false);
@ -108,6 +109,14 @@ export default function SettingsPage() {
[setShowBattery, ignoring],
);
const changePredictive = useCallback(
(enabled: boolean) => {
setPredictiveSets(enabled);
setItem('predictiveSets', enabled ? 'true' : 'false');
},
[setPredictiveSets],
);
return (
<View style={styles.container}>
<TextInput
@ -121,6 +130,7 @@ export default function SettingsPage() {
}}
style={styles.text}
/>
<TextInput
label="Rest seconds"
value={seconds}
@ -132,24 +142,35 @@ export default function SettingsPage() {
}}
style={styles.text}
/>
<Text style={styles.text}>Rest timers</Text>
<Switch
style={[styles.text, {alignSelf: 'flex-start'}]}
value={alarmEnabled}
onValueChange={changeAlarmEnabled}
/>
<Text style={styles.text}>Predictive sets</Text>
<Switch
style={[styles.text, {alignSelf: 'flex-start'}]}
value={predictiveSets}
onValueChange={changePredictive}
/>
<Button
style={{alignSelf: 'flex-start'}}
icon="arrow-down"
onPress={exportSets}>
Export
</Button>
<Button
style={{alignSelf: 'flex-start'}}
icon="arrow-up"
onPress={importSets}>
Import
</Button>
<Button
style={{alignSelf: 'flex-start', marginTop: 'auto'}}
icon="trash"