diff --git a/bob_party/App.tsx b/bob_party/App.tsx index 66568f5..7d15559 100644 --- a/bob_party/App.tsx +++ b/bob_party/App.tsx @@ -14,7 +14,7 @@ import StubUser from './src/services/userServices/stub'; -export const MANAGER_USER = new ManagerUser(new StubUser, new FakeSaverUser); +export const MANAGER_USER = new ManagerUser(new LoaderUserApi, new FakeSaverUser); export default function App() { diff --git a/bob_party/src/components/Skin.tsx b/bob_party/src/components/Skin.tsx index 5008344..25f0af7 100644 --- a/bob_party/src/components/Skin.tsx +++ b/bob_party/src/components/Skin.tsx @@ -10,6 +10,7 @@ import styles from "./style/Skin.style" import { useDispatch, useSelector } from "react-redux" import { loginUser } from "../redux/features/currentUserSlice" import { RootState } from "../redux/store" +import { MANAGER_USER } from "../../App" export const SkinComponent : /* Parameters : @@ -21,7 +22,6 @@ FC<{skin: Skin, state: String}> = { const dispatch=useDispatch(); - const currentUser = useSelector((state: RootState) => state.currentUserManager.currentUser); /* The display of this component depends of the screen from where it has been called: * From the TopBar (icon) : Small image in a circle @@ -49,7 +49,7 @@ FC<{skin: Skin, state: String}> = ) case 'liste': return( - {currentUser.setCurrentSkin(skin); dispatch(loginUser(currentUser))}} style={styles.imageWrapper}> + {MANAGER_USER.getCurrentUser().setCurrentSkin(skin)}} style={styles.imageWrapper}> {skin.getSkinName()} = ({nav, state}) => { - const currentUser = useSelector((state: RootState) => state.currentUserManager.currentUser); - /* The display of this component depends of the screen from where it has been called: * From the Settings (icon) : Name of the page + cross button * From other : skin + Title + parameters icon @@ -53,7 +52,7 @@ FC<{nav: any, state?: string}> = return ( nav.navigate('ProfileTab', {screen: 'Profile'})}> - + BOB PARTY nav.navigate('Settings')}> diff --git a/bob_party/src/constSex.ts b/bob_party/src/constSex.ts deleted file mode 100644 index 4e955d5..0000000 --- a/bob_party/src/constSex.ts +++ /dev/null @@ -1,9 +0,0 @@ - -const tabSex = [ - { label: "Homme", value: "Homme" }, - { label: "Femme", value: "Femme" }, - { label: "Non-binaire", value: "Non-binaire" }, - { label: "Autre", value: "Autre" }, -] - -export default tabSex; \ No newline at end of file diff --git a/bob_party/src/constSkin.ts b/bob_party/src/constSkin.ts new file mode 100644 index 0000000..473c83e --- /dev/null +++ b/bob_party/src/constSkin.ts @@ -0,0 +1,14 @@ +import { Skin } from "./core/skin"; + +let tabSkinApp:Skin[]=[ + new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), + new Skin("S0002", "Bob Blue",require('bob_party/assets/BobsSkins/BobBlue.png'), 100), + new Skin("S0003", "Bob BW",require('bob_party/assets/BobsSkins/BobBW.png'), 100), + new Skin("S0004", "Bob Green",require('bob_party/assets/BobsSkins/BobGreen.png'), 100), + new Skin("S0005", "Bob P&T",require('bob_party/assets/BobsSkins/BobPinkTurquoise.png'), 100), + new Skin("S0006", "Bob Red",require('bob_party/assets/BobsSkins/BobRed.png'), 100), + new Skin("S0007", "Bob Cute",require('bob_party/assets/BobsSkins/BobYellowGreenBlueHeart.png'), 100), +] + + +export default tabSkinApp; diff --git a/bob_party/src/core/Auth/login.ts b/bob_party/src/core/Auth/login.ts deleted file mode 100644 index 971d454..0000000 --- a/bob_party/src/core/Auth/login.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { loginUser } from '../../redux/features/currentUserSlice'; -import { updateIncorrectCredentials } from '../../redux/features/credentialErrorsSlice'; -import tabUS from "../../constUser"; -import { useSelector } from 'react-redux'; -import { RootState } from '../../redux/store'; - - - - - -export const checkCredentials = (login: string, password: string, dispatch: any, nav: any) => { - if((tabUS.map((User) => User.getUsername()).indexOf(login)) !== -1){ - let id = (tabUS.map((User) => User.getUsername()).indexOf(login)) - if ((tabUS.map((User) => User.getUsername()).indexOf(login) === id) && ( tabUS[id].getPassword() === password) ){ - dispatch(loginUser(tabUS[id])); - nav.navigate('HomeTab') - } - else{ - dispatch(updateIncorrectCredentials(true)) - } - } - else{ - dispatch(updateIncorrectCredentials(true)); - } -}; - diff --git a/bob_party/src/core/User/user.ts b/bob_party/src/core/User/user.ts index 40404b3..085dbec 100644 --- a/bob_party/src/core/User/user.ts +++ b/bob_party/src/core/User/user.ts @@ -30,7 +30,7 @@ export class User{ this.currentCoins=currentCoins; this.totalCoins=totalCoins; this.currentSkin=currentSkin; - this.tabSkin=tabSkin.copyWithin(tabSkin.length, 0); + this.tabSkin=[]; } diff --git a/bob_party/src/screens/Chat.tsx b/bob_party/src/screens/Chat.tsx index 3e9b1d1..4c3cabd 100644 --- a/bob_party/src/screens/Chat.tsx +++ b/bob_party/src/screens/Chat.tsx @@ -8,11 +8,11 @@ import { FlatList } from 'react-native-gesture-handler'; import { ConversationComponent } from '../components/ConversationComponent'; import { useSelector } from 'react-redux'; import { RootState } from '../redux/store'; +import { MANAGER_USER } from '../../App'; function Chat(props: { navigation: any; }) { const { navigation } = props - const currentUser = useSelector((state: RootState) => state.currentUserManager.currentUser); return ( @@ -20,10 +20,12 @@ function Chat(props: { navigation: any; }) { nav={navigation} /> + {/* } /> + */} state.currentUserManager.currentUser); return ( - {currentUser.getUsername()} + {MANAGER_USER.getCurrentUser().getUsername()} - {currentUser.getCurrentCoins()} + {MANAGER_USER.getCurrentUser().getCurrentCoins()} - + navigation.navigate('SkinList')} title='Changer de skin' state='Profile'/> - Total de BobCoin gagnés: {currentUser.getTotalCoins()} + Total de BobCoin gagnés: {MANAGER_USER.getCurrentUser().getTotalCoins()} state.setUser); + - const currentUser = useSelector((state: RootState) => state.currentUserManager.currentUser); const [dialogPseudoVisible, setDialogPseudoVisible] = useState(false); const [dialogPasswordVisible, setDialogPasswordVisible] = useState(false); @@ -26,6 +27,21 @@ function Settings(props: { navigation: any; }) { const [selectedSex, setSelectedSex] = useState(""); const [selectedNationality, setSelectedNationality] = useState(""); + + function changeUsername(username:string){ + MANAGER_USER.getCurrentUser()?.setUsername(username); + console.log(MANAGER_USER.getCurrentUser()?.getUsername()); + setUser(MANAGER_USER.getCurrentUser()); + MANAGER_USER.getsaverUser().updateUser(MANAGER_USER.getCurrentUser()); + } + + function changePassword(password:string){ + MANAGER_USER.getCurrentUser()?.setPassword(password); + console.log(MANAGER_USER.getCurrentUser()?.getPassword()); + setUser(MANAGER_USER.getCurrentUser()); + MANAGER_USER.getsaverUser().updateUser(MANAGER_USER.getCurrentUser()); + } + const dispatch=useDispatch(); return ( @@ -40,23 +56,23 @@ function Settings(props: { navigation: any; }) { - Pseudo: {currentUser.getUsername()} + Pseudo: {MANAGER_USER.getCurrentUser().getUsername()} setDialogPseudoVisible(true)} title='Changer le pseudo'/> - Mot de passe: {currentUser.getPassword()} - setDialogPasswordVisible(true)} title='Changer le mot de passe'/> + Mot de passe: {MANAGER_USER.getCurrentUser().getPassword()} + setDialogPasswordVisible(true) } title='Changer le mot de passe'/> - Nationalité: {currentUser.getNationality()} - setSelectedNationality(value)} donePress={() => dispatch(updateNationality(selectedNationality))} values={tabNat} /> + Nationalité: {MANAGER_USER.getCurrentUser().getNationality()} + setSelectedNationality(value)} donePress={() => dispatch(updateNationality(selectedNationality))} values={["Francais", "Anglais"]} /> - Sexe: {currentUser.getSexe()} - setSelectedSex(value)} donePress={() => dispatch(updateSex(selectedSex))} values={tabSex} /> + Sexe: {MANAGER_USER.getCurrentUser().getSexe()} + setSelectedSex(value)} donePress={() => dispatch(updateSex(selectedSex))} values={["Homme", "Femme", "Autre"]} /> - ID: {currentUser.getId()} + ID: {MANAGER_USER.getCurrentUser().getId()} @@ -65,7 +81,7 @@ function Settings(props: { navigation: any; }) { isDialogVisible={dialogPseudoVisible} title="Inserer le nouveau pseudo" hintInput ="Pseudo" - submitInput={ (inputText: string) => {dispatch(updatePseudo(inputText)); setDialogPseudoVisible(false)} } + submitInput={ (inputText: string) => { changeUsername(inputText); setDialogPseudoVisible(false)} } closeDialog={ () => {setDialogPseudoVisible(false)}}> @@ -73,8 +89,9 @@ function Settings(props: { navigation: any; }) { isDialogVisible={dialogPasswordVisible} title="Inserer le nouveau mot de passe" hintInput ="Mot de passe" - submitInput={ (inputText: string) => {dispatch(updatePassword(inputText)); setDialogPasswordVisible(false)} } + submitInput={ (inputText: string) => { changePassword(inputText); setDialogPasswordVisible(false)} } closeDialog={ () => {setDialogPasswordVisible(false)}}> + diff --git a/bob_party/src/screens/SignIn.tsx b/bob_party/src/screens/SignIn.tsx index ce1e681..794cf4e 100644 --- a/bob_party/src/screens/SignIn.tsx +++ b/bob_party/src/screens/SignIn.tsx @@ -1,22 +1,23 @@ import { StatusBar } from 'expo-status-bar' import { View, Pressable, Text, Alert} from 'react-native' -import React, { useState } from 'react'; +import React, { useCallback, useState } from 'react'; import stylesScreen from './style/screens.style' import { TextInput } from 'react-native-gesture-handler'; import styles from "./style/SignIn.style"; import { useDispatch, useSelector } from 'react-redux'; -import tabUS from '../constUser'; import { loginUser } from '../redux/features/currentUserSlice'; -import { checkCredentials } from '../core/Auth/login'; import { RootState } from '../redux/store'; import { updateIncorrectCredentials } from '../redux/features/credentialErrorsSlice'; import Dialog from "react-native-dialog"; +import { MANAGER_USER } from '../../App'; +import { useUserStore } from '../../userContext'; function SignIn(props: { navigation: any; }) { const { navigation } = props + const setUser = useUserStore((state) => state.setUser); const errorList = useSelector((state: RootState) => state.credentialErrors.loginErrorList); @@ -28,13 +29,29 @@ function SignIn(props: { navigation: any; }) { Alert.alert("Pseudo ou Mot de passe incorrect"); dispatch(updateIncorrectCredentials(true)); } + + + const handleUserConnect = useCallback(async (pseudo: string, password: string) => { + + const us =await MANAGER_USER.getLoaderUser().loadByUsernamePassword(pseudo, password).then((res) => { + if (res!=null){ + MANAGER_USER.setCurrentUser(res); + navigation.navigate('HomeTab'); + setUser(MANAGER_USER.getCurrentUser()); + } + else{ + console.log("wesh c'est null"); + } + }); + + }, []); return ( setPseudo(val)} autoCapitalize='none' /> setPassword(val)} autoCapitalize='none' secureTextEntry={true}/> - checkCredentials(pseudo, password, dispatch, navigation)}> + handleUserConnect(pseudo, password)}> Se connecter navigation.navigate('SignUp')}> diff --git a/bob_party/src/screens/SignUp.tsx b/bob_party/src/screens/SignUp.tsx index 3a14bc3..c5745da 100644 --- a/bob_party/src/screens/SignUp.tsx +++ b/bob_party/src/screens/SignUp.tsx @@ -10,8 +10,6 @@ import { useDispatch, useSelector } from 'react-redux'; import { checkNewUserValidity } from '../core/Auth/newUser'; import DateTimePicker, { DateTimePickerEvent } from '@react-native-community/datetimepicker'; import RNPickerSelect from "react-native-picker-select"; -import tabSex from '../constSex'; -import tabNat from '../constNat'; import { PickerGreySmall } from '../components/PickerGreySmall'; import { loginUser } from '../redux/features/currentUserSlice'; import { RootState } from '../redux/store'; @@ -121,12 +119,12 @@ function SignUp(props: { navigation: any; }) { Nationalité - setSelectedNationality(value)} values={tabNat} /> + setSelectedNationality(value)} values={["Français", "Anglais"]} /> Sexe - setSelectedSex(value)} values={tabSex} /> + setSelectedSex(value)} values={["Homme","Femme", "Autre"]} /> checkNewUserValidity(pseudo,password,date,selectedNationality,selectedSex, dispatch, navigation)}> S'inscrire diff --git a/bob_party/src/screens/Store.tsx b/bob_party/src/screens/Store.tsx index fbd0503..50c0478 100644 --- a/bob_party/src/screens/Store.tsx +++ b/bob_party/src/screens/Store.tsx @@ -9,11 +9,11 @@ import { SkinComponent } from '../components/Skin'; import { ScreenIndicator } from '../components/ScreenIndicator'; import { useSelector } from 'react-redux'; import { RootState } from '../redux/store'; +import { MANAGER_USER } from '../../App'; function Store(props: { navigation: any; }) { const { navigation } = props - const currentUser = useSelector((state: RootState) => state.currentUserManager.currentUser); return ( @@ -23,7 +23,7 @@ function Store(props: { navigation: any; }) { item.getSkinName()} diff --git a/bob_party/src/services/userServices/ISaverUser.ts b/bob_party/src/services/userServices/ISaverUser.ts index adb3c03..54e9a41 100644 --- a/bob_party/src/services/userServices/ISaverUser.ts +++ b/bob_party/src/services/userServices/ISaverUser.ts @@ -7,17 +7,17 @@ export default interface ISaverUser{ * u the user we want to save */ - saveUser(u:User): Promise; + saveUser(u:User | null): Promise; /** * deleteUser methode that delete a User in the data management system * u the user we want to delete */ - deleteUser(u:User):Promise; + deleteUser(u:User | null):Promise; /** * updateUser methode that update a User in the data management system * u the user we want to update */ - updateUser(u:User): Promise; + updateUser(u:User | null): Promise; } \ No newline at end of file diff --git a/bob_party/src/services/userServices/loaderUserApi.ts b/bob_party/src/services/userServices/loaderUserApi.ts index 3b6b239..3e49c16 100644 --- a/bob_party/src/services/userServices/loaderUserApi.ts +++ b/bob_party/src/services/userServices/loaderUserApi.ts @@ -1,5 +1,6 @@ import { Conversation } from "../../core/conversation"; import { Match } from "../../core/match"; +import { Skin } from "../../core/skin"; import { User } from "../../core/User/user"; import ILoaderUser from "./ILoaderUser"; @@ -87,32 +88,22 @@ export default class LoaderUserApi implements ILoaderUser{ return null; } - - async loadByUsernamePassword(username: string, password: string): Promise { - let test = new Test(true, 0, "wesh", 0); - try{ - await this.axios({ - method: 'get', - url: 'https://jsonplaceholder.typicode.com/todos/1', - params: { - name: "getUserForConnection", - username: username, - password: password, - //Les params genre nom de la fonction en php - } - }) - .then(function (response: any) { - console.log(response.data); - Object.assign(test, response.data); - console.log(test.id); - }); - }catch (error) { - console.error(error); - } - return null; + async loadByUsernamePassword(username: string, password: string): Promise{ + let user:User | null=null; + await this.axios({ + method: 'get', + url: 'https://jsonplaceholder.typicode.com/todos/1', + params: { + name: "getAllUser", + //Les params genre nom de la fonction en php + } + }) + .then(function (response: any) { + user=new User("U0001", username, password, "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]); + }); + return user; } - async loadUserByMatch(m: Match): Promise { throw new Error("Method not implemented."); }