-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timer renyi 48 #71
base: dev
Are you sure you want to change the base?
Timer renyi 48 #71
Changes from 4 commits
4ea6f52
1fa57f1
fe03e41
7d116eb
4fd55f0
a179a98
e17c26d
6951de6
b08b669
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
import React from "react"; | ||
import React, { useState, useEffect, useContext } from "react"; | ||
import { Box, Container, Grid, Typography } from "@material-ui/core"; | ||
import TimerIcon from "@material-ui/icons/Timer"; | ||
|
||
import { AppContext } from "../../App"; | ||
import { TEAM_ROLE } from "../game_lobby/team_select/TeamPresets"; | ||
|
||
function GamePrompt({ gameState, player }) { | ||
const { gameIO } = useContext(AppContext); | ||
|
||
const [timer, setTimer] = useState(45); | ||
|
||
let countDown = null; | ||
|
||
gameIO.state.io.on("start timer", () => { | ||
clearTimeout(countDown); | ||
setTimer(45) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add and use the server's countdown time to gameState.gameTurn (maybe as gameState.gameTurn.timeLeft). The reason for this is, if the user refreshes the page during the game, I believe the countdown time would be incorrect. By using the current countdown time from the gameState.gameTurn when the game page reloads, we can guarantee it to be accurate. |
||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be in its own useEffect(): |
||
|
||
useEffect(() => { | ||
if (timer > 0) { | ||
countDown = setTimeout(() => setTimer(timer - 1), 1000); | ||
} | ||
}); | ||
|
||
|
||
return ( | ||
<Container> | ||
<Grid container justify="space-between" alignItems="center"> | ||
|
@@ -14,7 +32,7 @@ function GamePrompt({ gameState, player }) { | |
<TimerIcon fontSize="large" /> | ||
</Grid> | ||
<Grid item> | ||
<Typography variant="h6">45s left</Typography> | ||
<Typography variant="h6">{timer}s left</Typography> | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [countdown, setCountDown] = useState(null);
variables that are not stateful can be inaccurate upon the page being rerendered