diff --git a/frontend/src/pages/Game.tsx b/frontend/src/pages/Game.tsx index 6074e64..81aeba0 100644 --- a/frontend/src/pages/Game.tsx +++ b/frontend/src/pages/Game.tsx @@ -1,13 +1,18 @@ -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import { useGameContext } from '../contexts/GameContext'; import Button from '../library/button'; import { useModal } from '../library/modal/ModalContext'; import CopyButton from '../library/copyButton'; import Chatbox from '../library/chatbox/Chatbox'; import { IoSettings } from 'react-icons/io5'; +import { useNavigate } from 'react-router-dom'; +import { triggerEvent } from '../channel'; +import { GameEventTypes } from '../../../backend/src/types'; function Game() { const { gameState } = useGameContext(); + const navigate = useNavigate(); + const [firstUser, setfirstuser] = useState(true); const modal = useModal(); useEffect(() => { if (gameState) { @@ -16,6 +21,14 @@ function Game() { // eslint-disable-next-line }, [gameState]); + function handleLeaveGame() { + triggerEvent({ + type: GameEventTypes.LEAVE_GAME, + data: null, + }); + navigate('/'); + } + function GamePropertiesModal() { return ( <> @@ -57,9 +70,22 @@ function Game() { /> - +
+ {firstUser && ( + + )} + +
);