import { FC, useState} from "react" import { Alert, Button, FlatList, Pressable } from "react-native" import React from "react" import { Game } from "../core/game" /* Importing the correct stylesheet */import { StatusBar } from 'expo-status-bar' import { View, Image, Text} from 'react-native' import stylesScreen from '../screens/style/screens.style' import style from './style/LobbyComponent.style' import { TopBar } from '../components/TopBar'; import { BotBar } from '../components/BotBar'; import { Conversation } from '../core/conversation'; import { BigBlueButton } from '../components/BigBlueButton'; import { useMatchStore } from '../context/matchContext'; import { MANAGER_MATCH } from '../../appManagers'; import { ScreenIndicator } from '../components/ScreenIndicator'; import { UserPreview } from "./UserPreview" import { socket } from "../../socketConfig" export const LobbyComponent : FC<{nav: any}> = ({nav}) => { const setTabUser = useMatchStore((state) => state.setTabUser); const setMatch = useMatchStore((state) => state.setMatch); const [initUsers, setInitUsers] = useState(0); const [init, setInit] = useState(0); function getUsers(){ if (initUsers===0){ setInitUsers(1); const tmp:any=[]; MANAGER_MATCH.getCurrentMatch()?.getTabUsers().forEach(user => { tmp.push(user); }); const tmpGame=MANAGER_MATCH.getCurrentMatch()?.getGame(); if (tmpGame!=undefined){ for (let i=tmp.length; itmpMatch.getTabUsers().length){ Alert.alert("Wait until there is enough players!"); return; } else if(tmpMatch.getGame().getNbPlayerMin(){ const match=MANAGER_MATCH.getCurrentMatch(); if (match !==null){ await MANAGER_MATCH.getLoaderMatch().loadByID(match.code).then((res) =>{ MANAGER_MATCH.setCurrentMatch(res); setMatch(res); setInitUsers(0); getUsers(); }); } }); socket.on("matchLaunched", async () =>{ nav.navigate(MANAGER_MATCH.getCurrentMatch()?.getGame().getName().replace(/\s/g, '')); }); } } initMatchSocket(); if(MANAGER_MATCH.getCurrentMatch()?.getGame().getNbPlayerMax()==1){ return ( nav.navigate(MANAGER_MATCH.getCurrentMatch()?.getGame().getName().replace(/\s/g, ''))} /> ); } else{ getUsers(); return( Match ID : {useMatchStore().match?.getCode()} usr?.getUsername() || usr} renderItem={({item}) => } style = {{width: '100%',}} /> {launchMatch()}} > Lancer la partie ); } }