diff --git a/bob_party/App.tsx b/bob_party/App.tsx index 57e11c0..f3badc9 100644 --- a/bob_party/App.tsx +++ b/bob_party/App.tsx @@ -1,20 +1,83 @@ -import React from 'react' -import { GameMulti } from './src/core/gameMulti' -import { GameSolo } from './src/core/gameSolo' -import { Match } from './src/core/match' -import { MatchMulti } from './src/core/matchMulti' -import MainTabNavigator from './src/navigation/AppNavigator' -import FakeSaverUser from './src/screens/services/userServices/fakeSaverUser' -import ManagerUser from './src/screens/services/userServices/ManagerUser' -import StubUser from './src/screens/services/userServices/stub' - - -export default function App() { - let m=new ManagerUser(new StubUser, new FakeSaverUser); - let tabU=m.getLoaderUser().loadAllUser(); - m.setCurrentUser(tabU[0]); - - let match= new MatchMulti("00001", [...tabU], new GameMulti("1", "SNAKE", require('./assets/Icons/UnSelected/Gamepad.png'),"ouin", 1, 1, new Map)); - console.log(m.getLoaderUser().loadUserByMatch(match)); - //return -} +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'; + + + +export const MANAGER_USER = new ManagerUser(new StubUser, new FakeSaverUser); + + + export default function App() { + const setUser = useUserStore((state) => state.setUser); + 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); + }); + setUser(MANAGER_USER.getCurrentUser()); + + + }, []); + + const handleUserLogout = useCallback(async () => { + // TODO: Call logout API + MANAGER_USER.setCurrentUser(null); + resetUser(); + }, []); + + const handleUserChange = useCallback(async () => { + MANAGER_USER.getCurrentUser()?.setCurrentCoins(MANAGER_USER.getCurrentUser()?.getCurrentCoins()+100); + 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/index.js b/bob_party/index.js index 1bf4263..bfdf9ba 100644 --- a/bob_party/index.js +++ b/bob_party/index.js @@ -2,10 +2,11 @@ import React from 'react' import App from './App' import store from './src/redux/store' import { Provider } from 'react-redux' +// export for others scripts to use -export default function Index(){ +export default function Index(){ return( /* diff --git a/bob_party/package.json b/bob_party/package.json index 2750c01..b10d8ba 100644 --- a/bob_party/package.json +++ b/bob_party/package.json @@ -15,9 +15,11 @@ "@react-navigation/native": "^6.0.13", "@react-navigation/stack": "^6.3.2", "@reduxjs/toolkit": "^1.8.6", + "axios": "^1.1.3", "expo": "^46.0.15", "expo-status-bar": "~1.4.0", "jest": "^26.6.3", + "jquery": "^3.6.1", "node": "^18.10.0", "react": "18.0.0", "react-dom": "18.0.0", @@ -28,11 +30,13 @@ "react-native-picker-select": "^8.0.4", "react-native-safe-area-context": "4.3.1", "react-native-web": "~0.18.7", - "react-redux": "^8.0.4" + "react-redux": "^8.0.4", + "zustand": "^4.1.4" }, "devDependencies": { "@babel/core": "^7.12.9", "@types/jest": "^29.1.2", + "@types/jquery": "^3.5.14", "@types/mocha": "^10.0.0", "@types/node": "^18.8.4", "@types/react": "~18.0.14", diff --git a/bob_party/src/core/User/managerCoinsUser.ts b/bob_party/src/core/User/managerCoinsUser.ts deleted file mode 100644 index 724a44c..0000000 --- a/bob_party/src/core/User/managerCoinsUser.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { User } from "./user"; - -export class ManagerCoinsUser{ - addCoins(u:User, coins:number){ - u.setCurrentCoins(u.getCurrentCoins()+coins); - u.setTotalCoins(u.getTotalCoins()+coins); - //modif dans la bdd - } - - removeCoins(u:User, coins:number){ - u.setCurrentCoins(u.getCurrentCoins()-coins); - //modif dans la bdd - } - - changeCurrentCoins(u:User, coins:number){ - u.setCurrentCoins(coins); - //modif dans la bdd - } -} \ No newline at end of file diff --git a/bob_party/src/core/User/user.ts b/bob_party/src/core/User/user.ts index 9f139f5..40404b3 100644 --- a/bob_party/src/core/User/user.ts +++ b/bob_party/src/core/User/user.ts @@ -4,6 +4,7 @@ import { sign } from 'crypto'; import { TextBase } from 'react-native'; export class User{ + readonly id: string; private username: string; private password: string; diff --git a/bob_party/src/core/User/userCoinsModifier.ts b/bob_party/src/core/User/userCoinsModifier.ts new file mode 100644 index 0000000..ee56c35 --- /dev/null +++ b/bob_party/src/core/User/userCoinsModifier.ts @@ -0,0 +1,23 @@ +import { MANAGER_USER } from "../../../App"; +import ManagerUser from "../../services/userServices/ManagerUser"; +import { User } from "./user"; + +export class ManagerCoinsUser{ + + + async addCoins(u:User, coins:number){ + u.setCurrentCoins(u.getCurrentCoins()+coins); + u.setTotalCoins(u.getTotalCoins()+coins); + await MANAGER_USER.getsaverUser().updateUser(u); + } + + async removeCoins(u:User, coins:number){ + u.setCurrentCoins(u.getCurrentCoins()-coins); + await MANAGER_USER.getsaverUser().updateUser(u); + } + + async changeCurrentCoins(u:User, coins:number){ + u.setCurrentCoins(coins); + await MANAGER_USER.getsaverUser().updateUser(u); + } +} \ No newline at end of file diff --git a/bob_party/src/core/User/userCreator.ts b/bob_party/src/core/User/userCreator.ts index 787f784..142a72b 100644 --- a/bob_party/src/core/User/userCreator.ts +++ b/bob_party/src/core/User/userCreator.ts @@ -1,12 +1,29 @@ import { User } from "./user"; import tabSkinApp from "../../constSkin"; import { Conversation } from "../conversation"; +import ManagerUser from "../../services/userServices/ManagerUser"; +import { MANAGER_USER } from "../../../App"; export class UserCreator{ - createUser(username:string, password:string, nationality:string, sexe:string, date:Date){ + + async createUser(username:string, password:string, nationality:string, sexe:string, date:Date){ //Récup l'ID d'après dans la bdd - const u = new User('0000', username, password, nationality, sexe, date, 0, 0, 0, tabSkinApp[0], [tabSkinApp[0]]); - //Ajout du joueur dans la bdd + let u:User; + let newId:string=""; + + let oldId = await MANAGER_USER.getLoaderUser().loadLastId(); + oldId=oldId.slice(1); + let leInt=parseInt(oldId); + newId+="U"; + for (let i = 0; i < 4-leInt.toString().length; i++) { + newId = newId + "0"; + } + leInt+=1; + newId=newId+leInt; + console.log(newId); + u = new User(newId, username, password, nationality, sexe, date, 0, 0, 0, tabSkinApp[0], [tabSkinApp[0]]); + await MANAGER_USER.getsaverUser().saveUser(u); + MANAGER_USER.setCurrentUser(u); return u; } } \ No newline at end of file diff --git a/bob_party/src/core/User/userModificationManager.ts b/bob_party/src/core/User/userModificationManager.ts index cf71bd8..808e0ac 100644 --- a/bob_party/src/core/User/userModificationManager.ts +++ b/bob_party/src/core/User/userModificationManager.ts @@ -1,24 +1,25 @@ +import { MANAGER_USER } from "../../../App"; import { User } from "./user"; export default class UserModificationManager{ - changePassword(user:User, password:string){ + async changePassword(user:User, password:string){ user.setPassword(password); - //modif dans la bdd + await MANAGER_USER.getsaverUser().updateUser(user); } - changeUsername(user:User, username:string){ + async changeUsername(user:User, username:string){ user.setPassword(username); - //modif dans la bdd + await MANAGER_USER.getsaverUser().updateUser(user); } - changeNationality(user:User, nationality:string){ + async changeNationality(user:User, nationality:string){ user.setNationality(nationality); - //modif dans la bdd + await MANAGER_USER.getsaverUser().updateUser(user); } - changeSexe(user:User, sexe:string){ + async changeSexe(user:User, sexe:string){ user.setSexe(sexe); - //modif dans la bdd + await MANAGER_USER.getsaverUser().updateUser(user); } } \ No newline at end of file diff --git a/bob_party/src/core/User/userSkinModifier.ts b/bob_party/src/core/User/userSkinModifier.ts index a842281..871afc4 100644 --- a/bob_party/src/core/User/userSkinModifier.ts +++ b/bob_party/src/core/User/userSkinModifier.ts @@ -1,13 +1,16 @@ +import { MANAGER_USER } from '../../../App'; import { Skin } from '../Skin' import { User } from './user' export default class UserSkinModifier{ - addSkin(user:User, skin:Skin){ + async addSkin(user:User, skin:Skin){ user.addSkin(skin); + await MANAGER_USER.getsaverUser().updateUser(user); } - changeCurrentSkin(user:User, skin:Skin){ + async changeCurrentSkin(user:User, skin:Skin){ user.setCurrentSkin(skin); + await MANAGER_USER.getsaverUser().updateUser(user); } } \ No newline at end of file diff --git a/bob_party/src/core/matchCasino.ts b/bob_party/src/core/matchCasino.ts index a41485f..7b229f0 100644 --- a/bob_party/src/core/matchCasino.ts +++ b/bob_party/src/core/matchCasino.ts @@ -2,7 +2,7 @@ import { Match } from "./match"; import { User } from "./User/user"; import { Game } from "./game"; import { GameCasino } from "./gameCasino"; -import { ManagerCoinsUser } from "./User/managerCoinsUser"; +import { ManagerCoinsUser } from "./User/userCoinsModifier"; export class MatchMulti extends Match{ diff --git a/bob_party/src/core/matchMulti.ts b/bob_party/src/core/matchMulti.ts index 255fc9a..6473f32 100644 --- a/bob_party/src/core/matchMulti.ts +++ b/bob_party/src/core/matchMulti.ts @@ -2,7 +2,7 @@ import { Match } from "./match"; import { User } from "./User/user"; import { Game } from "./game"; import { GameMulti } from "./gameMulti"; -import { ManagerCoinsUser } from "./User/managerCoinsUser"; +import { ManagerCoinsUser } from "./User/userCoinsModifier"; export class MatchMulti extends Match{ diff --git a/bob_party/src/core/matchSolo.ts b/bob_party/src/core/matchSolo.ts index 52f8efa..159c4cf 100644 --- a/bob_party/src/core/matchSolo.ts +++ b/bob_party/src/core/matchSolo.ts @@ -2,7 +2,7 @@ import { Match } from "./match"; import { GameSolo } from "./gameSolo"; import { User } from "./User/user"; import { Game } from "./game"; -import { ManagerCoinsUser } from "./User/managerCoinsUser"; +import { ManagerCoinsUser } from "./User/userCoinsModifier"; export class MatchSolo extends Match{ diff --git a/bob_party/src/screens/Home.tsx b/bob_party/src/screens/Home.tsx index bd05e30..3c5216d 100644 --- a/bob_party/src/screens/Home.tsx +++ b/bob_party/src/screens/Home.tsx @@ -16,10 +16,9 @@ let tabConv:Conversation[]=[]; function Home(props: { navigation: any; }) { + const { navigation } = props - - const currentUser = useSelector((state: RootState) => state.currentUser.value[0]); return ( diff --git a/bob_party/src/screens/services/userServices/loaderUserApi.ts b/bob_party/src/screens/services/userServices/loaderUserApi.ts deleted file mode 100644 index e2fbe06..0000000 --- a/bob_party/src/screens/services/userServices/loaderUserApi.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Conversation } from "../../../core/conversation"; -import { Match } from "../../../core/match"; -import { User } from "../../../core/User/user"; -import ILoaderUser from "./ILoaderUser"; - -export default class LoaderUserApi implements ILoaderUser{ - - async loadAllUser(): Promise { - throw new Error("Method not implemented."); - } - async loadByID(id: string): Promise { - throw new Error("Method not implemented."); - } - async loadByUsername(username: string): Promise { - throw new Error("Method not implemented."); - } - async loadByUsernamePassword(username: string, password: string): Promise { - throw new Error("Method not implemented."); - } - async loadUserByMatch(m: Match): Promise { - throw new Error("Method not implemented."); - } - async loadUserByConversation(c: Conversation): Promise { - throw new Error("Method not implemented."); - } - - - -} \ No newline at end of file diff --git a/bob_party/src/screens/services/conversationService/ILoaderConversation.ts b/bob_party/src/services/conversationService/ILoaderConversation.ts similarity index 87% rename from bob_party/src/screens/services/conversationService/ILoaderConversation.ts rename to bob_party/src/services/conversationService/ILoaderConversation.ts index 4435be0..cf6c4c9 100644 --- a/bob_party/src/screens/services/conversationService/ILoaderConversation.ts +++ b/bob_party/src/services/conversationService/ILoaderConversation.ts @@ -1,5 +1,5 @@ -import { Conversation } from "../../../core/conversation"; -import { User } from "../../../core/User/user"; +import { Conversation } from "../../core/conversation"; +import { User } from "../../core/User/user"; export default interface ILoaderConversation{ diff --git a/bob_party/src/screens/services/conversationService/ISaverConversation.ts b/bob_party/src/services/conversationService/ISaverConversation.ts similarity index 91% rename from bob_party/src/screens/services/conversationService/ISaverConversation.ts rename to bob_party/src/services/conversationService/ISaverConversation.ts index eaaae36..660c474 100644 --- a/bob_party/src/screens/services/conversationService/ISaverConversation.ts +++ b/bob_party/src/services/conversationService/ISaverConversation.ts @@ -1,4 +1,4 @@ -import { Conversation } from "../../../core/conversation"; +import { Conversation } from "../../core/conversation"; export default interface ISaverConversation{ diff --git a/bob_party/src/screens/services/matchServices/ILoaderMatch.ts b/bob_party/src/services/matchServices/ILoaderMatch.ts similarity index 90% rename from bob_party/src/screens/services/matchServices/ILoaderMatch.ts rename to bob_party/src/services/matchServices/ILoaderMatch.ts index c020b21..231ae1b 100644 --- a/bob_party/src/screens/services/matchServices/ILoaderMatch.ts +++ b/bob_party/src/services/matchServices/ILoaderMatch.ts @@ -1,4 +1,4 @@ -import { Match } from "../../../core/match"; +import { Match } from "../../core/match"; export default interface ILoaderMatch{ diff --git a/bob_party/src/screens/services/matchServices/ISaverMatch.ts b/bob_party/src/services/matchServices/ISaverMatch.ts similarity index 92% rename from bob_party/src/screens/services/matchServices/ISaverMatch.ts rename to bob_party/src/services/matchServices/ISaverMatch.ts index 7fbd664..4f261cd 100644 --- a/bob_party/src/screens/services/matchServices/ISaverMatch.ts +++ b/bob_party/src/services/matchServices/ISaverMatch.ts @@ -1,4 +1,4 @@ -import { Match } from "../../../core/match"; +import { Match } from "../../core/match"; export default interface ISaverMatch{ diff --git a/bob_party/src/screens/services/messageService/IMessageLoader.ts b/bob_party/src/services/messageService/IMessageLoader.ts similarity index 86% rename from bob_party/src/screens/services/messageService/IMessageLoader.ts rename to bob_party/src/services/messageService/IMessageLoader.ts index cb27871..e466fa3 100644 --- a/bob_party/src/screens/services/messageService/IMessageLoader.ts +++ b/bob_party/src/services/messageService/IMessageLoader.ts @@ -1,5 +1,5 @@ -import { Conversation } from "../../../core/conversation"; -import { Message } from "../../../core/message"; +import { Conversation } from "../../core/conversation"; +import { Message } from "../../core/message"; export default interface ILoaderMessage{ diff --git a/bob_party/src/screens/services/messageService/IMessageSaver.ts b/bob_party/src/services/messageService/IMessageSaver.ts similarity index 81% rename from bob_party/src/screens/services/messageService/IMessageSaver.ts rename to bob_party/src/services/messageService/IMessageSaver.ts index 3e328ee..195dc2a 100644 --- a/bob_party/src/screens/services/messageService/IMessageSaver.ts +++ b/bob_party/src/services/messageService/IMessageSaver.ts @@ -1,4 +1,4 @@ -import { Message } from "../../../core/message"; +import { Message } from "../../core/message"; export default interface ISaverMessage{ diff --git a/bob_party/src/screens/services/userServices/ILoaderUser.ts b/bob_party/src/services/userServices/ILoaderUser.ts similarity index 82% rename from bob_party/src/screens/services/userServices/ILoaderUser.ts rename to bob_party/src/services/userServices/ILoaderUser.ts index 0ffb1b9..aa700a4 100644 --- a/bob_party/src/screens/services/userServices/ILoaderUser.ts +++ b/bob_party/src/services/userServices/ILoaderUser.ts @@ -1,6 +1,6 @@ -import { Conversation } from "../../../core/conversation"; -import { Match } from "../../../core/match"; -import { User } from "../../../core/User/user"; +import { Conversation } from "../../core/conversation"; +import { Match } from "../../core/match"; +import { User } from "../../core/User/user"; export default interface ILoaderUser{ @@ -43,4 +43,10 @@ export default interface ILoaderUser{ * return an array of User */ loadUserByConversation(c:Conversation): Promise; + + /** + * loadLastId methode that load the last id used to create a user + * return a String + */ + loadLastId(): Promise; } \ No newline at end of file diff --git a/bob_party/src/screens/services/userServices/ISaverUser.ts b/bob_party/src/services/userServices/ISaverUser.ts similarity index 91% rename from bob_party/src/screens/services/userServices/ISaverUser.ts rename to bob_party/src/services/userServices/ISaverUser.ts index 9fbd862..adb3c03 100644 --- a/bob_party/src/screens/services/userServices/ISaverUser.ts +++ b/bob_party/src/services/userServices/ISaverUser.ts @@ -1,4 +1,4 @@ -import { User } from "../../../core/User/user"; +import { User } from "../../core/User/user"; export default interface ISaverUser{ diff --git a/bob_party/src/screens/services/userServices/ManagerUser.ts b/bob_party/src/services/userServices/ManagerUser.ts similarity index 79% rename from bob_party/src/screens/services/userServices/ManagerUser.ts rename to bob_party/src/services/userServices/ManagerUser.ts index 20b6db5..350e5d7 100644 --- a/bob_party/src/screens/services/userServices/ManagerUser.ts +++ b/bob_party/src/services/userServices/ManagerUser.ts @@ -1,17 +1,17 @@ -import { User } from "../../../core/User/user"; +import tabSkinApp from "../../constSkin"; +import { User } from "../../core/User/user"; import ILoaderUser from "./ILoaderUser"; import ISaverUser from "./ISaverUser"; export default class ManagerUser{ - private currentUser: User | null; + private currentUser: User | null=null; private loaderUser: ILoaderUser; private saverUser: ISaverUser; constructor(loader:ILoaderUser, saver:ISaverUser){ - this.currentUser=null; this.loaderUser=loader; this.saverUser=saver; } @@ -20,7 +20,7 @@ export default class ManagerUser{ return this.currentUser; } - setCurrentUser(u:User){ + setCurrentUser(u:User | null){ this.currentUser=u; } diff --git a/bob_party/src/screens/services/userServices/fakeSaverUser.ts b/bob_party/src/services/userServices/fakeSaverUser.ts similarity index 86% rename from bob_party/src/screens/services/userServices/fakeSaverUser.ts rename to bob_party/src/services/userServices/fakeSaverUser.ts index 09ff653..f85d8c4 100644 --- a/bob_party/src/screens/services/userServices/fakeSaverUser.ts +++ b/bob_party/src/services/userServices/fakeSaverUser.ts @@ -1,4 +1,4 @@ -import { User } from "../../../core/User/user"; +import { User } from "../../core/User/user"; import ISaverUser from "./ISaverUser"; diff --git a/bob_party/src/services/userServices/loaderUserApi.ts b/bob_party/src/services/userServices/loaderUserApi.ts new file mode 100644 index 0000000..3b6b239 --- /dev/null +++ b/bob_party/src/services/userServices/loaderUserApi.ts @@ -0,0 +1,140 @@ +import { Conversation } from "../../core/conversation"; +import { Match } from "../../core/match"; +import { User } from "../../core/User/user"; +import ILoaderUser from "./ILoaderUser"; + +class Test{ + public completed:boolean; + public id: number; + public title: String; + public userId: number; + + constructor(completed: boolean, id:number, title:String, userId: number){ + this.completed=completed; + this.id=id; + this.title=title; + this.userId=userId; + } +} + +export default class LoaderUserApi implements ILoaderUser{ + + private axios = require('axios').default; + + async loadAllUser() : Promise { + let test = new Test(true, 0, "wesh", 0); + 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) { + console.log(response.data); + Object.assign(test, response.data); + console.log(test.id); + }); + return []; + } + + + async loadByID(id: 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: "getUserById", + id: id, + //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 loadByUsername(username: 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: "getUserByUsername", + username: username, + //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 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 loadUserByMatch(m: Match): Promise { + throw new Error("Method not implemented."); + } + + + async loadUserByConversation(c: Conversation): Promise { + throw new Error("Method not implemented."); + } + + + async loadLastId(): Promise { + let test = new Test(true, 0, "wesh", 0); + try { + const response = await this.axios.get('https://jsonplaceholder.typicode.com/todos/1'); + console.log(response.data); + } catch (error) { + console.error(error); + } + return "U0001"; + } + + + + +} \ No newline at end of file diff --git a/bob_party/src/screens/services/userServices/saverUserApi.ts b/bob_party/src/services/userServices/saverUserApi.ts similarity index 54% rename from bob_party/src/screens/services/userServices/saverUserApi.ts rename to bob_party/src/services/userServices/saverUserApi.ts index 6883e4e..cff04b7 100644 --- a/bob_party/src/screens/services/userServices/saverUserApi.ts +++ b/bob_party/src/services/userServices/saverUserApi.ts @@ -1,11 +1,21 @@ -import { User } from "../../../core/User/user"; +import { User } from "../../core/User/user"; import ISaverUser from "./ISaverUser"; export default class SaverUserApi implements ISaverUser{ + private axios = require('axios').default; + async saveUser(u: User): Promise { - throw new Error("Method not implemented."); + this.axios({ + method: 'post', + url: '/user/12345', + data: { + firstName: 'Fred', + lastName: 'Flintstone' + } + }); + } async deleteUser(u: User): Promise { throw new Error("Method not implemented."); diff --git a/bob_party/src/screens/services/userServices/stub.ts b/bob_party/src/services/userServices/stub.ts similarity index 89% rename from bob_party/src/screens/services/userServices/stub.ts rename to bob_party/src/services/userServices/stub.ts index 1e2d32e..b654e81 100644 --- a/bob_party/src/screens/services/userServices/stub.ts +++ b/bob_party/src/services/userServices/stub.ts @@ -1,7 +1,7 @@ -import { Conversation } from "../../../core/conversation"; -import { Match } from "../../../core/match"; -import { Skin } from "../../../core/skin"; -import { User } from "../../../core/User/user"; +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"; export default class StubUser implements ILoaderUser{ @@ -48,6 +48,7 @@ export default class StubUser implements ILoaderUser{ }); return tabUser; } + async loadUserByConversation(c: Conversation): Promise { let tabUser:User[]=[]; c.getTabUser().forEach(u => { @@ -55,5 +56,9 @@ export default class StubUser implements ILoaderUser{ }); return tabUser; } + + async loadLastId(): Promise { + throw new Error("Method not implemented."); + } } \ No newline at end of file diff --git a/bob_party/userContext.tsx b/bob_party/userContext.tsx new file mode 100644 index 0000000..8696bab --- /dev/null +++ b/bob_party/userContext.tsx @@ -0,0 +1,18 @@ +import React from "react"; +import create from "zustand"; +import { User } from "./src/core/User/user"; + + +// Define store types +interface UserState { + user: User | null; + setUser: (user: User|null) => void; + resetUser: () => void; + } + +// Define store data and methods +export const useUserStore = create()((set, get) => ({ + user: null, + setUser: (user) => set((state) => ({ user: user })), + resetUser: () => set((state) => ({ user: undefined })), +})); diff --git a/bob_party/yarn.lock b/bob_party/yarn.lock index da77e66..6e36bb5 100644 --- a/bob_party/yarn.lock +++ b/bob_party/yarn.lock @@ -2254,6 +2254,13 @@ expect "^29.0.0" pretty-format "^29.0.0" +"@types/jquery@^3.5.14": + version "3.5.14" + resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.5.14.tgz#ac8e11ee591e94d4d58da602cb3a5a8320dee577" + integrity sha512-X1gtMRMbziVQkErhTQmSe2jFwwENA/Zr+PprCkF63vFq+Yt5PZ4AlKqgmeNlwgn7dhsXEK888eIW2520EpC+xg== + dependencies: + "@types/sizzle" "*" + "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.8": version "7.0.11" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" @@ -2315,6 +2322,11 @@ resolved "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz" integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew== +"@types/sizzle@*": + version "2.3.3" + resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.3.tgz#ff5e2f1902969d305225a047c8a0fd5c915cebef" + integrity sha512-JYM8x9EGF163bEyhdJBpR2QX1R5naCJHC8ucJylJ3w9/CVBaskdQ8WqBf8MmQrd1kRvp/a4TS8HJ+bxzR7ZJYQ== + "@types/source-list-map@*": version "0.1.2" resolved "https://registry.yarnpkg.com/@types/source-list-map/-/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9" @@ -2926,6 +2938,15 @@ atob@^2.1.2: resolved "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz" integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== +axios@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.1.3.tgz#8274250dada2edf53814ed7db644b9c2866c1e35" + integrity sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA== + dependencies: + follow-redirects "^1.15.0" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + babel-core@^7.0.0-bridge.0: version "7.0.0-bridge.0" resolved "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz" @@ -5483,7 +5504,7 @@ flush-write-stream@^1.0.0: inherits "^2.0.3" readable-stream "^2.3.6" -follow-redirects@^1.0.0: +follow-redirects@^1.0.0, follow-redirects@^1.15.0: version "1.15.2" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== @@ -5520,6 +5541,15 @@ form-data@^3.0.0, form-data@^3.0.1: combined-stream "^1.0.8" mime-types "^2.1.12" +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + forwarded@0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811" @@ -7323,6 +7353,11 @@ join-component@^1.1.0: resolved "https://registry.npmjs.org/join-component/-/join-component-1.1.0.tgz" integrity sha512-bF7vcQxbODoGK1imE2P9GS9aw4zD0Sd+Hni68IMZLj7zRnquH7dXUmMw9hDI5S/Jzt7q+IyTXN0rSg2GI0IKhQ== +jquery@^3.6.1: + version "3.6.1" + resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.1.tgz#fab0408f8b45fc19f956205773b62b292c147a16" + integrity sha512-opJeO4nCucVnsjiXOE+/PcCgYw9Gwpvs/a6B1LL/lQhwWwpbVEVYDZ1FokFr8PRc7ghYlrFPuyHuiiDNTQxmcw== + "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz" @@ -9567,6 +9602,11 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + prr@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476" @@ -11715,7 +11755,7 @@ use-latest-callback@^0.1.5: resolved "https://registry.npmjs.org/use-latest-callback/-/use-latest-callback-0.1.5.tgz" integrity sha512-HtHatS2U4/h32NlkhupDsPlrbiD27gSH5swBdtXbCAlc6pfOFzaj0FehW/FO12rx8j2Vy4/lJScCiJyM01E+bQ== -use-sync-external-store@^1.0.0: +use-sync-external-store@1.2.0, use-sync-external-store@^1.0.0: version "1.2.0" resolved "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz" integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA== @@ -12300,3 +12340,10 @@ yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== + +zustand@^4.1.4: + version "4.1.4" + resolved "https://registry.yarnpkg.com/zustand/-/zustand-4.1.4.tgz#b0286da4cc9edd35e91c96414fa54bfa4652a54d" + integrity sha512-k2jVOlWo8p4R83mQ+/uyB8ILPO2PCJOf+QVjcL+1PbMCk1w5OoPYpAIxy9zd93FSfmJqoH6lGdwzzjwqJIRU5A== + dependencies: + use-sync-external-store "1.2.0"