import React, {useEffect, useRef, useState} from 'react'; import {Card, Col, InputNumber, Row} from "antd" import {useSocket} from "use-socketio/lib"; import {NumberParam, useQueryParam} from 'use-query-params'; import {emit} from "../util/socket"; import "../css/lobby.sass"; import beer from "../img/beer.png" const Lobby = (props: any) => { const [lobbyId, setLobbyId] = useQueryParam('lobby', NumberParam); const [isLeader, setIsLeader] = useState(false); const [seekTime, setSeekTime] = useState(0); const [userCount, setUserCount] = useState(0); const {socket} = useSocket("welcome", async (obj: any) => { if (lobbyId) { // lobbyId is already defined, this means we have a queryparam set. await onChangeLobbyInput(lobbyId); return; } console.log("Got welcome", lobbyId); setLobbyId(obj.lobby.name); setIsLeader(socket.id === obj.lobby.leaderId); setUserCount(obj.lobby.users?.length || 0); }); const socketRef = useRef(socket); async function onChangeLobbyInput(i: any) { setLobbyId(i); const result: any = await emit(socket, 'join_lobby', i); setIsLeader(socket.id === result.lobby.leaderId); setUserCount(result.lobby.users?.length || 0); } useEffect(() => { async function wrapper() { const result: any = await emit(socketRef.current, 'lobby_info'); setIsLeader(socketRef.current.id === result.lobby.leaderId); setUserCount(result.lobby.users?.length || 0); } wrapper(); }, []); const seekItem = ( Start bij: setSeekTime(time || 0)}/> sec. ); return (

beerCenturion! beer

Honderd minuten...
Honderd shots...
Kun jij het aan?
{ await emit(socket, 'request_start', seekTime) }}>Start, ] : [ Join ]}> Huidige lobby

Er zijn {userCount} gebruiker(s) aanwezig.

{isLeader ? 'Jij bent de baas.' : 'Wachten op de baas...'}

{isLeader ? seekItem : ''}
); }; export default Lobby;