Merge branch 'Persistance' of https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY into Persistance

Persistance
Mathilde JEAN 2 years ago
commit 0d16bcaa54

@ -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 (
<View style={stylesScreen.bodyCenter}>
<AUser />
<Button onPress={handleUserConnect} title="Connect"></Button>
<Button onPress={handleUserLogout} title="Logout"></Button>
<Button onPress={handleUserChange} title="testChangement"></Button>
</View>
<MainTabNavigator/>
);
}
const AUser = () => {
const userName = useUserStore((state) => state.user?.getUsername());
const test = useUserStore((state) => state.user?.getCurrentCoins());
return userName === undefined ? (
<Text>Not Connected</Text>
) : (
<View>
<Text>Hello {userName}</Text>
<Text>Money {test}</Text>
</View>
);
};

@ -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,
})

@ -6,24 +6,23 @@ 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 (
<View style={stylesScreen.container}>
<TopBar
nav={navigation}
/>
<View style={stylesScreen.bodyStart}>
{/*
<FlatList
data={currentUser.getTabConv()}
renderItem={({item}) => <ConversationComponent conv={item} state='Preview'/>}
/>
*/}
</View>
<BotBar
nav={navigation}

@ -8,8 +8,7 @@ import { BotBar } from '../components/BotBar';
import { SkinComponent } from '../components/Skin';
import { ButtonGreySmall } from '../components/ButtonGreySmall';
import { ScreenIndicator } from '../components/ScreenIndicator';
import { useSelector } from 'react-redux';
import { RootState } from '../redux/store';
import { MANAGER_USER } from '../../App';
const coin = require('../../assets/Icons/Coin.png')
@ -18,7 +17,6 @@ const coin = require('../../assets/Icons/Coin.png')
function Profile(props: { navigation: any; }) {
const { navigation } = props
const currentUser = useSelector((state: RootState) => state.currentUser.value)[0];
return (
<View style={stylesScreen.container}>
@ -27,22 +25,22 @@ function Profile(props: { navigation: any; }) {
/>
<View style={stylesScreen.bodyStart}>
<ScreenIndicator title='Profil'/>
<Text style={styles.pseudoText}>{currentUser.getUsername()}</Text>
<Text style={styles.pseudoText}>{MANAGER_USER.getCurrentUser().getUsername()}</Text>
<View style={styles.coinSkinView}>
<View style={styles.coinView}>
<Image
style={styles.coin}
source={coin}
/>
<Text style={styles.coinText}>{currentUser.getCurrentCoins()}</Text>
<Text style={styles.coinText}>{MANAGER_USER.getCurrentUser().getCurrentCoins()}</Text>
</View>
<View style={styles.skinView}>
<SkinComponent skin={currentUser.getCurrentSkin()} state='profile' />
<SkinComponent skin={MANAGER_USER.getCurrentUser().getCurrentSkin()} state='profile' />
<ButtonGreySmall onPress={() => navigation.navigate('SkinList')} title='Changer de skin' state='Profile'/>
</View>
</View>
<View style={styles.infoView}>
<Text style={styles.infoText}>Total de BobCoin gagnés: {currentUser.getTotalCoins()}</Text>
<Text style={styles.infoText}>Total de BobCoin gagnés: </Text>
</View>
</View>
<BotBar

@ -7,12 +7,11 @@ import { TopBar } from '../components/TopBar';
import { ButtonGreySmall } from '../components/ButtonGreySmall';
import { useDispatch, useSelector } from 'react-redux';
import { RootState } from '../redux/store';
import DialogInput from "react-native-dialog-input";
import { updatePseudo, updatePassword, updateNationality, updateSex } from "../redux/features/currentUserSlice";
import Dialog from "react-native-dialog"
import RNPickerSelect from "react-native-picker-select";
import tabNat from '../constNat';
import tabSex from '../constSex';
import DialogInput from 'react-native-dialog/lib/Input';
function Settings(props: { navigation: any; }) {
const { navigation } = props
@ -66,7 +65,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) => { setDialogPseudoVisible(false)} }
closeDialog={ () => {setDialogPseudoVisible(false)}}>
</DialogInput>
@ -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)}}>
</DialogInput>
@ -88,7 +87,7 @@ function Settings(props: { navigation: any; }) {
/>
</View>
<Dialog.Button label="Cancel" onPress={() => setDialogNationalityVisible(false)} />
<Dialog.Button label="Valider" onPress={() => {dispatch(updateNationality(selectedNationality)); setDialogNationalityVisible(false)}} />
<Dialog.Button label="Valider" onPress={() => { setDialogNationalityVisible(false)}} />
</Dialog.Container>
<Dialog.Container visible={dialogSexVisible}>
@ -101,7 +100,7 @@ function Settings(props: { navigation: any; }) {
/>
</View>
<Dialog.Button label="Cancel" onPress={() => setDialogSexVisible(false)} />
<Dialog.Button label="Valider" onPress={() => {dispatch(updateSex(selectedSex)); setDialogSexVisible(false)}} />
<Dialog.Button label="Valider" onPress={() => { setDialogSexVisible(false)}} />
</Dialog.Container>
</View>

@ -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 (
<View style={stylesScreen.container}>
<View style={stylesScreen.bodyCenter}>
{/*
<TextInput style={styles.textInput} placeholder='Login' onChangeText={(val) => setPseudo(val)} autoCapitalize='none' />
<TextInput style={styles.textInput} placeholder='Password' onChangeText={(val) => setPassword(val)} autoCapitalize='none' />
<Pressable style={styles.button} onPress={() => userVerif(pseudo, password, navigation)}>
<Text style={styles.text}>Se connecter</Text>
</Pressable>
*/}
<Pressable onPress={() => navigation.navigate('SignUp')}>
<Text style={styles.signup}>Pas de compte? Inscrivez vous !</Text>
</Pressable>

@ -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 (
<View style={stylesScreen.container}>

@ -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 (
<View style={stylesScreen.container}>
@ -23,7 +21,7 @@ function Store(props: { navigation: any; }) {
<View style={stylesScreen.bodyStart}>
<ScreenIndicator title='Store'/>
<FlatList
data={currentUser.getTabSkin()}
data={MANAGER_USER.getCurrentUser().getTabSkin()}
numColumns={2}
columnWrapperStyle={{ flex: 1, justifyContent: "space-around"}}
keyExtractor={item =>item.getSkinName()}

@ -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<User[]> {
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);
}

Loading…
Cancel
Save