From 8d4286c5e2953d007d9d10dc7de112b0278a8a2d Mon Sep 17 00:00:00 2001 From: SpencerHC Date: Tue, 2 Jul 2024 20:31:39 -0600 Subject: [PATCH] Added working review view --- game/src/index.ts | 16 +++++++++------- ui/src/Board.tsx | 18 ++++-------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/game/src/index.ts b/game/src/index.ts index 2721eea..896254c 100644 --- a/game/src/index.ts +++ b/game/src/index.ts @@ -54,19 +54,21 @@ const moves: Moves = { const { answer, index } = payload as WritePayload; const { round } = board; playerboard.answers[round][index] = answer; - //Go to review phase when any player has entered 10 answers - if (playerboard.answers[round].some(a => a !== "")) { + if (playerboard.answers[round].every(a => a.length > 0)) { board.phase = "review" as const; } }, - }, - [REVIEW]: { - executeNow({ board, playerboard, userId }) { + execute({ board, playerboards }) { + if(board.phase !== "review"){ + return; + } board.answers = {}; - board.answers[userId] = playerboard.answers[board.round]; - }, + for (const [userId, playerboard] of Object.entries(playerboards)) { + board.answers![userId] = playerboard.answers[board.round]; + } } + } }; const game: GameDef = { diff --git a/ui/src/Board.tsx b/ui/src/Board.tsx index 03c0945..eb8bd3b 100644 --- a/ui/src/Board.tsx +++ b/ui/src/Board.tsx @@ -104,7 +104,6 @@ function AnswerInput({ index }: { index: number }) { const { value } = e.target; setNewAnswer(value); dispatch(write({ index, answer: value })); - checkPhase(); }} onFocus={() => setFocused(true)} onBlur={() => setFocused(false)} @@ -113,17 +112,6 @@ function AnswerInput({ index }: { index: number }) { ); } -function checkPhase () { - const phase = useSelector((state) => state.board.phase); - const userId = useSelector( - (state) => state.playerboard.userId - ); - const dispatch = useDispatch(); - if (phase === 'review') { - dispatch(review(userId)); - } -} - function ReviewContent () { const userIds = useSelector((state) => state.board.userIds) return ( @@ -135,14 +123,13 @@ function ReviewContent () { function Player({userId}: {userId: UserId}) { const username = useUsername(userId); - const round = useSelector((state) => state.board.round) const roundStep = useSelector((state) => state.board.roundStep) const answers = useSelector((state) => state.board.answers![userId]) const answer = answers[roundStep]; return(
-
{username}
+
{username}
{answer}
) @@ -152,6 +139,8 @@ function Board() { useFonts(); const phase = useSelector((state) => state.board.phase); const numCategories = useSelector((state) => state.board.categories.length); + const roundstep = useSelector((state) => state.board.roundStep) + const category = useSelector((state) => state.board.categories[roundstep]) if(phase === 'write'){ return (
@@ -173,6 +162,7 @@ function Board() {
+
{category}
{ReviewContent()}