diff --git a/app/+not-found.tsx b/app/+not-found.tsx index 45c0b68..068a869 100644 --- a/app/+not-found.tsx +++ b/app/+not-found.tsx @@ -1,4 +1,4 @@ -import { Link, Stack } from 'expo-router'; +import { Stack } from 'expo-router'; import { StyleSheet } from 'react-native'; import { Text, View } from '@/components/shared/Themed'; diff --git a/app/RootStackParamList.ts b/app/RootStackParamList.ts index 309d108..fe7d722 100644 --- a/app/RootStackParamList.ts +++ b/app/RootStackParamList.ts @@ -1,4 +1,5 @@ export type RootStackParamList = { - dashboard: undefined; - timer: { reps: number, restTime: number, workTime: number}; + Dashboard: undefined; + Timer: { reps: number, restTime: number, workTime: number}; + Settings: undefined; }; diff --git a/app/Settings.tsx b/app/Settings.tsx new file mode 100644 index 0000000..9753fb4 --- /dev/null +++ b/app/Settings.tsx @@ -0,0 +1,80 @@ +import React, { useEffect, useState } from 'react'; + +import { Text } from '@/components/shared/Themed'; +import styled from '@emotion/native'; +import { useNavigation } from '@react-navigation/native'; +import { NativeStackNavigationProp } from '@react-navigation/native-stack'; +import { RootStackParamList } from '@/app/RootStackParamList'; +import { loadUserSettings, saveUserSettings } from '@/components/shared/business/AsyncStorage'; +import { Switch } from 'react-native'; +import { VerticalSpacer } from '@/components/shared/Spacers'; +import Button from '@/components/shared/Button'; + +type NavigationProp = NativeStackNavigationProp; + +export default function Dashboard() { + const navigation = useNavigation(); + const [soundEnabled, setSoundEnabled] = useState(false); + + useEffect(() => { + const init = async () => { + try { + const soundEnabledLocal = await loadUserSettings('soundEnabled'); + console.log('soundEnabledLocal', soundEnabledLocal); + + if (soundEnabledLocal === null) { + console.log('soundEnabledLocal is null'); + setSoundEnabled(true); + } else { + console.log('soundEnabledLocal is present', ); + setSoundEnabled(Boolean(Number(soundEnabledLocal))); + } + } catch (error) { + throw new Error('Erreur lors du chargement des paramètres utilisateur'); + } + }; + + init(); + }, []); + + useEffect(() => { + saveUserSettings('soundEnabled', String(Number(soundEnabled))); + }, [soundEnabled]); + + return ( + + Preferences + +