From 2a633cb3f4735665d2c5e1769fa2a591a346487f Mon Sep 17 00:00:00 2001 From: Torpenn Date: Sun, 13 Oct 2024 23:18:08 +0200 Subject: [PATCH] feat: add settings page --- app/+not-found.tsx | 2 +- app/RootStackParamList.ts | 5 +- app/Settings.tsx | 80 +++++++++++++++++++ app/_layout.tsx | 11 +-- app/dashboard.tsx | 8 +- app/timer.tsx | 21 ++++- .../useCases/timer/view/FinishContent.tsx | 4 +- .../useCases/timer/view/TimerContent.tsx | 4 +- 8 files changed, 118 insertions(+), 17 deletions(-) create mode 100644 app/Settings.tsx 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 + +