Add max number of sets to settings page

This commit is contained in:
Brandon Presley 2022-07-10 19:03:07 +12:00
parent 530d6d6fb9
commit aa780172a4
3 changed files with 19 additions and 2 deletions

View File

@ -51,6 +51,7 @@ const App = () => {
if (alarmEnabled === null) await setItem('alarmEnabled', 'false'); if (alarmEnabled === null) await setItem('alarmEnabled', 'false');
if (!(await getItem('predictiveSets'))) if (!(await getItem('predictiveSets')))
await setItem('predictiveSets', 'true'); await setItem('predictiveSets', 'true');
if (!(await getItem('maxSets'))) await setItem('maxSets', '3');
}; };
init(); init();
}, []); }, []);

View File

@ -163,7 +163,9 @@ export default function HomePage() {
set => set.name === todaysSets[0].name, set => set.name === todaysSets[0].name,
).length; ).length;
console.log(`${HomePage.name}.onAdd: count =`, count); console.log(`${HomePage.name}.onAdd: count =`, count);
if (count < 3) return setNewSet({...todaysSets[0], id: undefined, created}); const maxSets = await AsyncStorage.getItem('maxSets');
if (count < Number(maxSets))
return setNewSet({...todaysSets[0], id: undefined, created});
const nextWorkout = const nextWorkout =
todaysWorkouts[todaysWorkouts.indexOf(todaysSets[0].name!) + 1]; todaysWorkouts[todaysWorkouts.indexOf(todaysSets[0].name!) + 1];
if (!nextWorkout) if (!nextWorkout)

View File

@ -18,6 +18,7 @@ const {getItem, setItem} = AsyncStorage;
export default function SettingsPage() { export default function SettingsPage() {
const [minutes, setMinutes] = useState<string>(''); const [minutes, setMinutes] = useState<string>('');
const [maxSets, setMaxSets] = useState<string>('3');
const [seconds, setSeconds] = useState<string>(''); const [seconds, setSeconds] = useState<string>('');
const [alarmEnabled, setAlarmEnabled] = useState<boolean>(false); const [alarmEnabled, setAlarmEnabled] = useState<boolean>(false);
const [predictiveSets, setPredictiveSets] = useState<boolean>(false); const [predictiveSets, setPredictiveSets] = useState<boolean>(false);
@ -31,8 +32,10 @@ export default function SettingsPage() {
setMinutes((await getItem('minutes')) || ''); setMinutes((await getItem('minutes')) || '');
setSeconds((await getItem('seconds')) || ''); setSeconds((await getItem('seconds')) || '');
setAlarmEnabled((await getItem('alarmEnabled')) === 'true'); setAlarmEnabled((await getItem('alarmEnabled')) === 'true');
setPredictiveSets((await getItem('predictiveSets')) === 'true');
setMaxSets((await getItem('maxSets')) || '');
NativeModules.AlarmModule.ignoringBatteryOptimizations(setIgnoring); NativeModules.AlarmModule.ignoringBatteryOptimizations(setIgnoring);
}, [setIgnoring]); }, []);
useEffect(() => { useEffect(() => {
refresh(); refresh();
@ -144,6 +147,17 @@ export default function SettingsPage() {
style={styles.text} style={styles.text}
/> />
<TextInput
label="Max sets"
value={maxSets}
keyboardType="numeric"
onChangeText={value => {
setMaxSets(value);
setItem('maxSets', value);
}}
style={styles.text}
/>
<Text style={styles.text}>Rest timers</Text> <Text style={styles.text}>Rest timers</Text>
<Switch <Switch
style={[styles.text, {alignSelf: 'flex-start'}]} style={[styles.text, {alignSelf: 'flex-start'}]}