Skip to content

Commit

Permalink
gamapage: Added a LEAVE GAME button in Modal
Browse files Browse the repository at this point in the history
Added a Leave game button in GamePropertiesModal
which triggers the LEAVE_GAME event and navigates
to homepage.

fixes #161
  • Loading branch information
sksmagr23 committed Jun 25, 2024
1 parent 71bbdbc commit 4f341c6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions frontend/src/pages/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ 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 modal = useModal();
useEffect(() => {
if (gameState) {
Expand All @@ -16,6 +20,14 @@ function Game() {
// eslint-disable-next-line
}, [gameState]);

function handleLeaveGame() {
triggerEvent({
type: GameEventTypes.LEAVE_GAME,
data: null,
});
navigate('/');
}

function GamePropertiesModal() {
return (
<>
Expand Down Expand Up @@ -57,9 +69,14 @@ function Game() {
/>
</h2>
</div>
<Button type={'submit'} onClick={() => modal.hide()}>
Join Game
</Button>
<div className="flex gap-5">
<Button type={'submit'} onClick={() => modal.hide()}>
Join Game
</Button>
<Button type={'button'} onClick={handleLeaveGame}>
Leave Game
</Button>
</div>
</div>
</>
);
Expand Down

0 comments on commit 4f341c6

Please sign in to comment.