diff --git a/src/components/views/Gameroom.tsx b/src/components/views/Gameroom.tsx index 0b0fe2a..36db523 100644 --- a/src/components/views/Gameroom.tsx +++ b/src/components/views/Gameroom.tsx @@ -44,11 +44,14 @@ const Gameroom = () => { console.log(user) const [showReadyPopup, setShowReadyPopup] = useState(false); const [gameOver, setGameOver] = useState(false); + const gameOverRef = useRef(false); const [currentSpeakerID, setCurrentSpeakerID] = useState(null); const [playerLists, setPlayerLists] = useState([]); const roundFinished = useRef(false); const [endTime, setEndTime] = useState(null); - const gameTheme = useRef(null); + const gameTheme = useRef("Loading...."); + const leaderboardInfoRecieved = useRef(false); + const [leaderboardInfo, setLeaderboardInfo] = useState([]); const [gameInfo, setGameInfo] = useState(null); const gameInfoRef = useRef(null); @@ -161,6 +164,10 @@ const Gameroom = () => { console.log(roundFinished.current); } } + if (gameOverRef.current === true && leaderboardInfoRecieved.current === false){ + setLeaderboardInfo(payloadData.message); + leaderboardInfoRecieved.current = true; + } }; const onGameInfoReceived = (payload) => { @@ -182,6 +189,7 @@ const Gameroom = () => { setShowReadyPopup(true); } else if (payloadData.message.gameStatus === "over") { setShowReadyPopup(false); + gameOverRef.current = true; setGameOver(true); } else { setShowReadyPopup(false); @@ -464,60 +472,67 @@ const Gameroom = () => { console.log(playerLists); const LeaderBoard = ({ playerStatus }) => { + // console.log("123456") + console.log("[LeaderBoard]",playerStatus) + return ( -
-
- {playerStatus.map((playerInfo, index) => ( -
- {index + 1} - - - - - {playerInfo.user.name} - - - {playerInfo.score.total} - - + <> + {playerStatus !== null && ( +
+
+ {playerStatus.map((playerInfo, index) => ( +
+ {index + 1} + + + + + {playerInfo.user.name} + + + {playerInfo.score.total} + + Total - - - {playerInfo.score.guess} - - + + + {playerInfo.score.guess} + + Guess - - - {playerInfo.score.read} - - - Read - - {playerInfo.score.details.map((detail, detailIndex) => ( - - - {detail.score} - - - {detail.word} + + {playerInfo.score.read} - + + Read + + {playerInfo.score.details.map((detail, detailIndex) => ( + + + {detail.score} + + + + {detail.word} + + + ))} +
))}
- ))} -
-
+
+ )} + ); }; @@ -575,7 +590,7 @@ const Gameroom = () => {
{"Room#" + currentRoomName} - {gameTheme.current} + {gameTheme.current} {" "} Ready to start the game? @@ -621,7 +636,7 @@ const Gameroom = () => {
)} {gameOver && ( - + )} {!gameOver && !showReadyPopup && (