diff --git a/src/FLAD/navigation/AuthNavigation.tsx b/src/FLAD/navigation/AuthNavigation.tsx index 8c220dd..031d2c7 100644 --- a/src/FLAD/navigation/AuthNavigation.tsx +++ b/src/FLAD/navigation/AuthNavigation.tsx @@ -1,5 +1,5 @@ import Navigation from './Navigation'; -import { StyleSheet, SafeAreaView } from 'react-native'; +import { StyleSheet, SafeAreaView, AsyncStorage } from 'react-native'; import { SafeAreaProvider } from 'react-native-safe-area-context'; import StartNavigation from './StartNavigation'; import { Provider, useDispatch, useSelector } from 'react-redux'; @@ -7,7 +7,7 @@ import store from '../redux/store'; import { useCallback, useEffect, useState } from 'react'; import * as SplashScreen from 'expo-splash-screen'; import { View } from 'react-native'; -import { getRefreshToken } from '../redux/thunk/authThunk'; +import { ChangeMode, getRefreshToken } from '../redux/thunk/authThunk'; import * as Location from 'expo-location'; // const LOCATION_TASK_NAME = 'flad-background-location-task'; @@ -60,16 +60,28 @@ export default function AuthNavigation() { // }; // }, []); + async function prepare() { + //@ts-ignore + await dispatch(getRefreshToken()) + if (tokenProcesed && appIsReady) { + await SplashScreen.hideAsync(); + } // await SplashScreen.hideAsync(); + } + async function ChangeDarkMode() { + try { + const currentValue = await AsyncStorage.getItem('dark'); + if (currentValue !== null) { + const newValue = JSON.stringify(JSON.parse(currentValue)); + dispatch(ChangeMode(JSON.parse(newValue))) + } + } catch (error) { + console.log(`Une erreur s'est produite lors de la mise à jour de la valeur booléenne pour la clé 'dark': `, error); + } + } useEffect(() => { - async function prepare() { - //@ts-ignore - await dispatch(getRefreshToken()) - if (tokenProcesed && appIsReady) { - await SplashScreen.hideAsync(); - } // await SplashScreen.hideAsync(); - } + ChangeDarkMode(); prepare(); }, [appIsReady, tokenProcesed]); diff --git a/src/FLAD/navigation/Navigation.tsx b/src/FLAD/navigation/Navigation.tsx index a5d3b55..8ee9e98 100644 --- a/src/FLAD/navigation/Navigation.tsx +++ b/src/FLAD/navigation/Navigation.tsx @@ -21,7 +21,7 @@ import SpotifyService from '../services/spotify/spotify.service'; export default function Navigation() { const isDark = useSelector(state => state.userReducer.dark); - const style = isDark ? GraphicalCharterLight : GraphicalCharterDark; + const style = isDark ? GraphicalCharterDark : GraphicalCharterLight; const BottomTabNavigator = createBottomTabNavigator(); const MyTheme = { dark: false, diff --git a/src/FLAD/redux/actions/userActions.tsx b/src/FLAD/redux/actions/userActions.tsx index fb6aac4..42f175e 100644 --- a/src/FLAD/redux/actions/userActions.tsx +++ b/src/FLAD/redux/actions/userActions.tsx @@ -19,10 +19,11 @@ export interface CredentialsRegister { // loggedInState, // } // ); -export const setLoginState = (cred: Credentials) => { +export const setLoginState = (userJson: any) => { + const user = new User(userJson.data.idFlad,userJson.data.idSpotify,userJson.data.email,new Date(),userJson.data.name, require('../../assets/images/jul.png')); return { type: userTypes.LOGIN, - playload: cred + playload: user }; } diff --git a/src/FLAD/redux/thunk/authThunk.tsx b/src/FLAD/redux/thunk/authThunk.tsx index e746279..f68d286 100644 --- a/src/FLAD/redux/thunk/authThunk.tsx +++ b/src/FLAD/redux/thunk/authThunk.tsx @@ -8,6 +8,7 @@ import { Credentials, CredentialsRegister, restoreToken, setLoginState, UserLogo import * as SecureStore from 'expo-secure-store'; import { User } from "../../Model/User"; import { UserFactory } from "../../Model/factory/UserFactory"; +import * as ImagePicker from 'expo-image-picker'; const key = 'userToken'; @@ -97,6 +98,7 @@ export const userLogin = (loginCredential: Credentials) => { ) // dispatch(setLoginState(resp.data.user) ); // our action is called here console.log(user.data); + dispatch(setLoginState(user.data)); // our action is called here } else { console.log('Login Failed', 'Username or Password is incorrect'); @@ -156,6 +158,14 @@ export const ChangeMode = (value: boolean) => { } } +export const ChangeImageUserCurrent = (value: ImagePicker) => { + //@ts-ignore + return async dispatch => { + dispatch(userChangeImage(value)); + } +} + + // const logIn = (email, password) => { // const action = (dispatch) => { // if (email === user.email && password === user.password) { diff --git a/src/FLAD/screens/Setting.tsx b/src/FLAD/screens/Setting.tsx index 3cc487b..c5d9185 100644 --- a/src/FLAD/screens/Setting.tsx +++ b/src/FLAD/screens/Setting.tsx @@ -33,16 +33,8 @@ export default function Setting() { const currentMusic = useSelector(state => state.appReducer.userCurrentMusic); //Dark Mode - const [isDark, setIsDark] = useState(null); - useEffect(() => { - const retrieveDarkMode = async () => { - const darkModeValue = await AsyncStorage.getItem('dark'); - if (darkModeValue !== null) { - setIsDark(JSON.parse(darkModeValue)); - } - }; - retrieveDarkMode(); - }, []); + const isDark = useSelector(state => state.userReducer.dark); + const style = isDark ? GraphicalCharterDark : GraphicalCharterLight; async function ChangeDarkMode() { @@ -51,7 +43,6 @@ export default function Setting() { if (currentValue !== null) { const newValue = JSON.stringify(!JSON.parse(currentValue)); await AsyncStorage.setItem('dark', newValue); - setIsDark(JSON.parse(newValue)); dispatch(ChangeMode(JSON.parse(newValue))) } } catch (error) { diff --git a/src/FLAD/screens/SettingProfil.tsx b/src/FLAD/screens/SettingProfil.tsx index c0bf5e6..b3caee4 100644 --- a/src/FLAD/screens/SettingProfil.tsx +++ b/src/FLAD/screens/SettingProfil.tsx @@ -4,7 +4,7 @@ import { TextInput, TouchableOpacity } from 'react-native-gesture-handler'; import { Svg, Path } from 'react-native-svg'; import Modal from "react-native-modal"; import { useNavigation } from "@react-navigation/native"; -import { useSelector } from 'react-redux'; +import { useDispatch, useSelector } from 'react-redux'; import normalize from '../components/Normalize'; import * as ImagePicker from 'expo-image-picker'; @@ -23,23 +23,20 @@ const DismissKeyboard = ({ children }) => ( export default function SettingProfil() { //Dark Mode - const [isDark, setIsDark] = useState(null); - useEffect(() => { - const retrieveDarkMode = async () => { - const darkModeValue = await AsyncStorage.getItem('dark'); - if (darkModeValue !== null) { - setIsDark(JSON.parse(darkModeValue)); - } - }; - retrieveDarkMode(); - }, []); + const dispatch = useDispatch(); + const isDark = useSelector(state => state.userReducer.dark); + const UserCurrent = useSelector(state => state.userReducer.user); + const style = isDark ? GraphicalCharterDark : GraphicalCharterLight; - const [image, setImage] = useState(null); const navigation = useNavigation(); const [currentIndex, setCurrentIndex] = useState(0); const [isModalVisible, setIsModalVisible] = React.useState(false); + useEffect(() => { + console.log(UserCurrent.image); + }); + const handleModal = () => setIsModalVisible(() => !isModalVisible); // @ts-ignore const viewableItemsChanged = useRef(({ viewableItems }) => { @@ -54,11 +51,7 @@ export default function SettingProfil() { aspect: [4, 3], quality: 1, }); - - console.log(result); - if (!result.canceled) { - setImage(result.assets[0].uri); } }; @@ -182,12 +175,12 @@ export default function SettingProfil() { textInputId: { marginLeft: 50, width: '57%', - color: 'white', + color: style.Text, fontSize: normalize(18), }, textInputMail: { marginLeft: 100, - color: 'white', + color: style.Text, width: '57%', fontSize: normalize(18) }, @@ -288,7 +281,7 @@ export default function SettingProfil() { Profil - {image && } + @@ -301,11 +294,11 @@ export default function SettingProfil() { Identifiant - + Mail - +