From 624d4b415d57b19f4bd889bc1ebf6daae55c669a Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Tue, 19 Mar 2024 21:18:55 +0800 Subject: [PATCH] fix: game end not getting the correct room status bug --- pages/rooms/[roomId]/index.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pages/rooms/[roomId]/index.tsx b/pages/rooms/[roomId]/index.tsx index d3aa601c..8ddcdd2f 100644 --- a/pages/rooms/[roomId]/index.tsx +++ b/pages/rooms/[roomId]/index.tsx @@ -47,6 +47,7 @@ export default function Room() { const player = roomInfo.players.find( (player) => player.id === currentUser?.id ); + const isHost = roomInfo.host.id === currentUser?.id; useEffect(() => { async function getRoomInfo() { @@ -101,6 +102,7 @@ export default function Room() { firePopup({ title: `遊戲已結束!`, }); + fetch(getRoomInfoEndpoint(roomId)).then(initializeRoom); }); socket.on(SOCKET_EVENT.ROOM_CLOSED, () => { @@ -113,6 +115,7 @@ export default function Room() { token, socket, currentUser?.id, + roomId, addPlayer, removePlayer, updateUserReadyStatus, @@ -120,6 +123,8 @@ export default function Room() { updateRoomStatus, replace, firePopup, + fetch, + initializeRoom, ]); // Event: kick user @@ -169,10 +174,9 @@ export default function Room() { }; firePopup({ - title: - roomInfo.host.id === currentUser?.id - ? `當您離開房間後,房主的位子將會自動移交給其他成員,若房間內沒有成員則會自動關閉房間,是否確定要離開房間?` - : `是否確定要離開房間?`, + title: isHost + ? `當您離開房間後,房主的位子將會自動移交給其他成員,若房間內沒有成員則會自動關閉房間,是否確定要離開房間?` + : `是否確定要離開房間?`, showCancelButton: true, onConfirm: leave, }); @@ -216,8 +220,8 @@ export default function Room() { onClickClose={handleClickClose} onClickLeave={handleLeave} onClickStart={handleStart} - isHost={roomInfo.host.id === currentUser?.id} - isReady={player?.isReady || false} + isHost={isHost} + isReady={isHost || !!player?.isReady} /> {gameUrl && }