Skip to content

Commit

Permalink
Update GamePage.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
ijun17 authored Nov 21, 2024
1 parent 968cfa7 commit eded0cd
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion FE/src/pages/GamePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { Modal } from '../components/Modal';
import { useState, useEffect } from 'react';
import { GameHeader } from '@/components/GameHeader';
import { HeaderBar } from '@/components/HeaderBar';
import { socketService } from '@/api/socket';
import { socketService, useSocketException } from '@/api/socket';
import { useParams } from 'react-router-dom';
import { useRoomStore } from '@/store/useRoomStore';
import { QuizHeader } from '@/components/QuizHeader';
import GameState from '@/constants/gameState';
import { usePlayerStore } from '@/store/usePlayerStore';
import { ResultModal } from '@/components/ResultModal';
import { ErrorModal } from '@/components/ErrorModal';
import { useNavigate } from 'react-router-dom';

export const GamePage = () => {
const { gameId } = useParams<{ gameId: string }>();
Expand All @@ -25,6 +27,7 @@ export const GamePage = () => {
const [isErrorModalOpen, setIsErrorModalOpen] = useState(false);
const [errorModalTitle, setErrorModalTitle] = useState('');
const [isResultOpen, setIsResultOpen] = useState(false);
const navigate = useNavigate();

useEffect(() => {
updateRoom({ gameId });
Expand All @@ -40,6 +43,11 @@ export const GamePage = () => {
if (gameState === GameState.END) setIsResultOpen(true);
}, [gameState]);

useSocketException('joinRoom', (data) => {
setErrorModalTitle(data);
setIsErrorModalOpen(true);
});

const handleNameSubmit = (name: string) => {
setCurrentPlayerName(name);
setIsModalOpen(false); // 이름이 μ„€μ •λ˜λ©΄ λͺ¨λ‹¬ λ‹«κΈ°
Expand Down Expand Up @@ -82,6 +90,13 @@ export const GamePage = () => {
onClose={() => setIsModalOpen(false)}
onSubmit={handleNameSubmit}
/>

<ErrorModal
isOpen={isErrorModalOpen}
title={errorModalTitle}
buttonText="메인 νŽ˜μ΄μ§€λ‘œ 이동"
onClose={() => navigate('/')}
/>
</div>
</div>
</>
Expand Down

0 comments on commit eded0cd

Please sign in to comment.