2ème push pour alban
continuous-integration/drone/push Build is failing Details

Persistance
Thomas Chazot 2 years ago
parent 3b19f61e8e
commit 14f75a0429

@ -11,9 +11,11 @@ import styles from './style/Game.style';
import LobbySolo from "../screens/LobbySolo" import LobbySolo from "../screens/LobbySolo"
import ManagerMatch from "../services/matchServices/managerMatch" import ManagerMatch from "../services/matchServices/managerMatch"
import MatchCreator from "../core/Match/matchCreator" import MatchCreator from "../core/Match/matchCreator"
import { MANAGER_USER } from "../../App" import { MANAGER_MATCH, MANAGER_USER } from "../../App"
import { useMatchStore } from "../context/matchContext"
export const GameComponent : export const GameComponent :
/* /*
* game : Game that must be displayed * game : Game that must be displayed
* nav : tool needed to allow the navigation between the screens * nav : tool needed to allow the navigation between the screens
@ -22,24 +24,32 @@ FC<{game: Game, nav: any}> =
({game, nav}) => ({game, nav}) =>
{ {
const setMatch = useMatchStore((state) => state.setMatch);
async function createNewMatchSolo(game : Game, nav: any) {
const m=new MatchCreator();
let tmp=MANAGER_USER.getCurrentUser();
if (tmp!=null){
let match=await m.createMatch(tmp, game);
MANAGER_MATCH.setCurrentMatch(match);
setMatch(match);
nav.navigate("LobbySolo");
}
}
return ( return (
<View> <View>
<Pressable onPress={() => createNewMatchSolo(game, nav)}> <Pressable onPress={() => createNewMatchSolo(game, nav)}>
<Image <Image
style={styles.image} style={styles.image}
source={{uri: game.getImageSource()}} source={{uri: useMatchStore().match?.getGame().getImageSource()}}
/> />
<Text style={styles.name}>{game.getName()}</Text> <Text style={styles.name}>{game.getName()}</Text>
</Pressable> </Pressable>
</View> </View>
) )
}
function createNewMatchSolo(game : Game, nav: any) {
const m=new MatchCreator();
let tmp=MANAGER_USER.getCurrentUser();
if (tmp!=null){
let match=m.createMatch(tmp, game);
nav.navigate("LobbySolo");
}
} }

@ -0,0 +1,18 @@
import React from "react";
import create from "zustand";
import { Match } from "../core/Match/match";
// Define store types
interface MatchState {
match: Match | null;
setMatch: (match: Match|null) => void;
resetMatch: () => void;
}
// Define store data and methods
export const useMatchStore = create<MatchState>()((set, get) => ({
match: null,
setMatch: (match) => set((state) => ({ match: match })),
resetMatch: () => set((state) => ({ match: null })),
}));

@ -14,5 +14,5 @@ interface UserState {
export const useUserStore = create<UserState>()((set, get) => ({ export const useUserStore = create<UserState>()((set, get) => ({
user: null, user: null,
setUser: (user) => set((state) => ({ user: user })), setUser: (user) => set((state) => ({ user: user })),
resetUser: () => set((state) => ({ user: undefined })), resetUser: () => set((state) => ({ user: null })),
})); }));

Loading…
Cancel
Save