From a297958ca0aa68ffcdaa0699c14dffd0a758143b Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 22 Nov 2022 11:11:14 +0100 Subject: [PATCH] DELETE: Redux user --- bob_party/App.tsx | 51 ++++--------------- bob_party/src/redux/store.ts | 2 - bob_party/src/screens/Chat.tsx | 7 ++- bob_party/src/screens/Profile.tsx | 12 ++--- bob_party/src/screens/Settings.tsx | 11 ++-- bob_party/src/screens/SignIn.tsx | 8 +-- bob_party/src/screens/SkinList.tsx | 3 -- bob_party/src/screens/Store.tsx | 6 +-- .../services/userServices/loaderUserApi.ts | 17 ++++--- 9 files changed, 40 insertions(+), 77 deletions(-) diff --git a/bob_party/App.tsx b/bob_party/App.tsx index f3badc9..73eba52 100644 --- a/bob_party/App.tsx +++ b/bob_party/App.tsx @@ -1,18 +1,13 @@ import LoaderUserApi from './src/services/userServices/loaderUserApi' import ManagerUser from './src/services/userServices/ManagerUser' import FakeSaverUser from './src/services/userServices/fakeSaverUser' -import { View, Text, Button } from 'react-native'; import React, { useCallback } from 'react'; import { useUserStore } from './userContext'; -import stylesScreen from './src/screens/style/screens.style' -import { User } from './src/core/User/user'; -import tabSkinApp from './src/constSkin'; -import { stat } from 'fs'; -import StubUser from './src/services/userServices/stub'; +import MainTabNavigator from './src/navigation/AppNavigator'; -export const MANAGER_USER = new ManagerUser(new StubUser, new FakeSaverUser); +export const MANAGER_USER = new ManagerUser(new LoaderUserApi, new FakeSaverUser); export default function App() { @@ -20,21 +15,7 @@ export const MANAGER_USER = new ManagerUser(new StubUser, new FakeSaverUser); const resetUser = useUserStore((state) => state.resetUser); const handleUserConnect = useCallback(async () => { - /* - fetch(GET_USER_URL) - .then((res) => { - if (res.status === 200) { - return res.json(); - } - throw new Error("Bad User"); - }) - .then((user) => { - setUser(user); - }) - .catch((err) => { - console.log(err); - }); - */ + await MANAGER_USER.getLoaderUser().loadByID("14").then((res) => { MANAGER_USER.setCurrentUser(res); console.log(res); @@ -56,28 +37,16 @@ export const MANAGER_USER = new ManagerUser(new StubUser, new FakeSaverUser); }, []); + const test = useCallback(async () => { + const tab = await MANAGER_USER.getLoaderUser().loadAllUser(); + MANAGER_USER.setCurrentUser(tab[0]); + setUser(MANAGER_USER.getCurrentUser()); + }, []); + return ( - - - - - - + ); } - - const AUser = () => { - const userName = useUserStore((state) => state.user?.getUsername()); - const test = useUserStore((state) => state.user?.getCurrentCoins()); - return userName === undefined ? ( - Not Connected - ) : ( - - Hello {userName} - Money {test} - - ); - }; diff --git a/bob_party/src/redux/store.ts b/bob_party/src/redux/store.ts index 2f9f420..f2a06d5 100644 --- a/bob_party/src/redux/store.ts +++ b/bob_party/src/redux/store.ts @@ -1,5 +1,4 @@ import { configureStore } from "@reduxjs/toolkit"; -import currentUserReducer from "./features/currentUserSlice"; import { getDefaultMiddleware } from '@reduxjs/toolkit'; const customizedMiddleware = getDefaultMiddleware({ @@ -8,7 +7,6 @@ const customizedMiddleware = getDefaultMiddleware({ const store = configureStore({ reducer: { - currentUser: currentUserReducer, }, middleware: (getDefaultMiddleware) => customizedMiddleware, }) diff --git a/bob_party/src/screens/Chat.tsx b/bob_party/src/screens/Chat.tsx index dedaabf..2f81007 100644 --- a/bob_party/src/screens/Chat.tsx +++ b/bob_party/src/screens/Chat.tsx @@ -6,13 +6,10 @@ import { TopBar } from '../components/TopBar'; import { BotBar } from '../components/BotBar'; import { FlatList } from 'react-native-gesture-handler'; import { ConversationComponent } from '../components/ConversationComponent'; -import { useSelector } from 'react-redux'; -import { RootState } from '../redux/store'; + function Chat(props: { navigation: any; }) { const { navigation } = props - - const currentUser = useSelector((state: RootState) => state.currentUser.value[0]); return ( @@ -20,10 +17,12 @@ function Chat(props: { navigation: any; }) { nav={navigation} /> + {/* } /> + */} state.currentUser.value)[0]; return ( @@ -27,22 +25,22 @@ function Profile(props: { navigation: any; }) { /> - {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: {dispatch(updatePseudo(inputText)); setDialogPseudoVisible(false)} } + submitInput={ (inputText: string) => { setDialogPseudoVisible(false)} } closeDialog={ () => {setDialogPseudoVisible(false)}}> @@ -74,7 +73,7 @@ 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) => {setDialogPasswordVisible(false)} } closeDialog={ () => {setDialogPasswordVisible(false)}}> @@ -88,7 +87,7 @@ function Settings(props: { navigation: any; }) { /> setDialogNationalityVisible(false)} /> - {dispatch(updateNationality(selectedNationality)); setDialogNationalityVisible(false)}} /> + { setDialogNationalityVisible(false)}} /> @@ -101,7 +100,7 @@ function Settings(props: { navigation: any; }) { /> setDialogSexVisible(false)} /> - {dispatch(updateSex(selectedSex)); setDialogSexVisible(false)}} /> + { setDialogSexVisible(false)}} /> diff --git a/bob_party/src/screens/SignIn.tsx b/bob_party/src/screens/SignIn.tsx index ad7414b..e668eef 100644 --- a/bob_party/src/screens/SignIn.tsx +++ b/bob_party/src/screens/SignIn.tsx @@ -5,16 +5,15 @@ import stylesScreen from './style/screens.style' import { TextInput } from 'react-native-gesture-handler'; import tabUS from "../constUser"; import styles from "./style/SignIn.style" -import { useDispatch, } from 'react-redux'; -import { loginUser } from '../redux/features/currentUserSlice'; function SignIn(props: { navigation: any; }) { - const { navigation } = props + const { navigation } = props + {/* const [pseudo, setPseudo] = useState(''); const [password, setPassword] = useState(''); @@ -29,15 +28,18 @@ function SignIn(props: { navigation: any; }) { } } } +*/} return ( + {/* setPseudo(val)} autoCapitalize='none' /> setPassword(val)} autoCapitalize='none' /> userVerif(pseudo, password, navigation)}> Se connecter + */} navigation.navigate('SignUp')}> Pas de compte? Inscrivez vous ! diff --git a/bob_party/src/screens/SkinList.tsx b/bob_party/src/screens/SkinList.tsx index 94b5faa..49736ca 100644 --- a/bob_party/src/screens/SkinList.tsx +++ b/bob_party/src/screens/SkinList.tsx @@ -8,15 +8,12 @@ import { FlatList } from 'react-native-gesture-handler'; import { SkinComponent } from '../components/Skin'; import tabSkinApp from '../constSkin'; import { ScreenIndicator } from '../components/ScreenIndicator'; -import { useSelector } from 'react-redux'; -import { RootState } from '../redux/store'; function SkinList(props: { navigation: any; }) { const { navigation } = props - const currentUser = useSelector((state: RootState) => state.currentUser.value[0]); return ( diff --git a/bob_party/src/screens/Store.tsx b/bob_party/src/screens/Store.tsx index def6f0d..8f0ab85 100644 --- a/bob_party/src/screens/Store.tsx +++ b/bob_party/src/screens/Store.tsx @@ -7,13 +7,11 @@ import { BotBar } from '../components/BotBar'; import { FlatList } from 'react-native-gesture-handler'; 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.currentUser.value[0]); return ( @@ -23,7 +21,7 @@ function Store(props: { navigation: any; }) { item.getSkinName()} diff --git a/bob_party/src/services/userServices/loaderUserApi.ts b/bob_party/src/services/userServices/loaderUserApi.ts index 3b6b239..b456804 100644 --- a/bob_party/src/services/userServices/loaderUserApi.ts +++ b/bob_party/src/services/userServices/loaderUserApi.ts @@ -1,3 +1,4 @@ +import tabSkinApp from "../../constSkin"; import { Conversation } from "../../core/conversation"; import { Match } from "../../core/match"; import { User } from "../../core/User/user"; @@ -22,21 +23,23 @@ export default class LoaderUserApi implements ILoaderUser{ private axios = require('axios').default; async loadAllUser() : Promise { - let test = new Test(true, 0, "wesh", 0); + let us:User[]=[]; + let test=new Test(false, 1, "a", 1); await this.axios({ method: 'get', - url: 'https://jsonplaceholder.typicode.com/todos/1', + url: 'https://jsonplaceholder.typicode.com/todos', params: { name: "getAllUser", //Les params genre nom de la fonction en php } }) .then(function (response: any) { - console.log(response.data); + if (response.data != null && response.data != undefined){ Object.assign(test, response.data); - console.log(test.id); - }); - return []; + us.push(new User("17", "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[6], tabSkinApp)); + } + }); + return us; } @@ -60,7 +63,7 @@ export default class LoaderUserApi implements ILoaderUser{ }catch (error) { console.error(error); } - return null; + return new User("17", "Bite", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 123, 123324, 12, tabSkinApp[6], tabSkinApp); }