Skip to content
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

Fix wise man stack timer #356

Merged
merged 4 commits into from
Apr 28, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions webapp/src/pages/games/WiseMenStackGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const WiseMenStackGame = () => {
const [timerRunning, setTimerRunning] = React.useState(true); // indicate if the timer is working
const [showConfetti, setShowConfetti] = React.useState(false); //indicates if the confetti must appear
const [questionCountdownKey, ] = React.useState(60); //key to update question timer
const [targetTime, ] = React.useState(60);
const [questionCountdownRunning, setQuestionCountdownRunning] = React.useState(false); //property to start and stop question timer
const [userResponses, setUserResponses] = React.useState([]);
const [language, setCurrentLanguage] = React.useState(i18n.language);
Expand All @@ -64,19 +65,22 @@ const WiseMenStackGame = () => {

// hook to initiating new rounds if the current number of rounds is less than or equal to 3
React.useEffect(() => {
if (totalTimePlayed <= questionCountdownKey) {
if (totalTimePlayed <= targetTime) {
startNewRound();
setQuestionCountdownRunning(true);
} else {
setTimerRunning(false);
setShouldRedirect(true);
setQuestionCountdownRunning(false);
updateStatistics();
updateQuestionsRecord();
setQuestionCountdownRunning(true)
}
// eslint-disable-next-line
}, [round]);

const endGame = () => {
setTimerRunning(false);
setShouldRedirect(true);
setQuestionCountdownRunning(false);
updateStatistics();
updateQuestionsRecord();
// eslint-disable-next-line
}

// stablish if the confetti must show or not
React.useEffect(() => {
if (correctlyAnsweredQuestions > incorrectlyAnsweredQuestions) {
Expand Down Expand Up @@ -108,7 +112,7 @@ const WiseMenStackGame = () => {
setQuestionData(quest.data[0]);
setButtonStates(new Array(2).fill(null));
getPossibleOptions(quest.data[0]);

}).catch(error => {
console.error("Could not get questions", error);
});
Expand Down Expand Up @@ -182,6 +186,7 @@ const WiseMenStackGame = () => {

// this function is called when a user selects a response.
const selectResponse = async (index, response) => {
setQuestionCountdownRunning(false);
setAnswered(true);
const newButtonStates = [...buttonStates];

Expand Down Expand Up @@ -332,7 +337,7 @@ const WiseMenStackGame = () => {
<CssBaseline />

<Container sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }} >
{ answered ?
{ false ?
// Pausa
<IconButton variant="contained" size="large" color="primary" aria-label={ paused ? t("Game.play") : t("Game.pause") }
onClick={() => togglePause()} sx={{ height: 100, width: 100, border: `2px solid ${theme.palette.primary.main}` }}
Expand All @@ -341,8 +346,8 @@ const WiseMenStackGame = () => {
</IconButton>
:
// Cronómetro
<CountdownCircleTimer data-testid="circleTimer" key={questionCountdownKey} isPlaying = {questionCountdownRunning} duration={60} colorsTime={[10, 6, 3, 0]}
colors={[theme.palette.success.main, "#F7B801", "#f50707", theme.palette.error.main]} size={100} onComplete={() => selectResponse(-1, "FAILED")}>
<CountdownCircleTimer data-testid="circleTimer" key={questionCountdownKey} isPlaying = {questionCountdownRunning} duration={targetTime} colorsTime={[10, 6, 3, 0]}
colors={[theme.palette.success.main, "#F7B801", "#f50707", theme.palette.error.main]} size={100} onComplete={() => endGame()}>
{({ remainingTime }) => {
return (
<Box style={{ display: 'flex', alignItems: 'center' }}>
Expand Down
Loading