Skip to content

Commit

Permalink
Added working review view
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerHC committed Jul 3, 2024
1 parent cad12be commit 8d4286c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
16 changes: 9 additions & 7 deletions game/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,21 @@ const moves: Moves<B, PB> = {
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<B, PB> = {
Expand Down
18 changes: 4 additions & 14 deletions ui/src/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -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 (
Expand All @@ -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(
<div className={classNames(!answer && 'opacity-70')}>
<div>{username}</div>
<div><b>{username}</b></div>
<div>{answer}</div>
</div>
)
Expand All @@ -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 (
<div className="flex flex-col items-center justify-center w-full h-full overflow-hidden">
Expand All @@ -173,6 +162,7 @@ function Board() {
<div className="flex flex-col items-center justify-center w-full h-full overflow-hidden">
<div className="w-full max-w-96 h-full max-h-vmd bg-neutral-50 flex flex-col rounded">
<Header />
<div className="flex justify-center">{category}</div>
<div className="flex-1 flex flex-col justify-between p-2 vmd:p-3 space-y-3.5 overflow-y-auto">
{ReviewContent()}
</div>
Expand Down

0 comments on commit 8d4286c

Please sign in to comment.