Skip to content

Commit

Permalink
Hotfix with the storage of calculator game
Browse files Browse the repository at this point in the history
  • Loading branch information
alegarman2002 committed May 2, 2024
1 parent 8796566 commit c0dd63a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion webapp/src/components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Button from './Button'
import { Footer } from './footer/Footer';
import { Nav } from './nav/Nav';
import axios from 'axios';
import { generateGameId } from './Util';

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT|| 'http://localhost:8000';

Expand All @@ -31,7 +32,8 @@ const Menu = () => {
}

const initiateCalculator = async () => {
navigation("/calculator")
let gameId = await generateGameId();
navigation("/calculator", {state: {gameId}})
}

return (
Expand Down
16 changes: 10 additions & 6 deletions webapp/src/components/game/Calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import { Container, Typography, Box, LinearProgress } from '@mui/material';
import { Footer } from '../footer/Footer';
import { Nav } from '../nav/Nav';
import Button from '../Button';
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';

let questions = [];
let load = true;
const previousBackgroundColor = '#1a1a1a';
let points = 0;
let answeredQuestions = [];
let enter = false


const Calculator = () => {

let username = localStorage.getItem("username")
const [questionIndex, setQuestionIndex] = useState(0);
const id = generateGameId();
let id = useLocation().state.gameId;

const navigator = useNavigate();

const [remTime, setRemTime] = useState(0);
const [totalTime, setTotalTime] = useState(0);

if(questions.length === 0)
generateQuestion();
Expand All @@ -31,9 +31,13 @@ const Calculator = () => {
const time = setInterval(() => {
setRemTime((progress) => {
if(progress === 100){
setTotalTime(totalTime + (80-progress/10)/questions.length)
gameStore(id, username, points, answeredQuestions, totalTime/answeredQuestions.length);
init();
console.log("Imprimimos id", id)
console.log("Answered questions", answeredQuestions)
let avgtime = 80/questions.length
if (!enter) {
gameStore(id, username, points, answeredQuestions, avgtime);
init();
}
navigator('/menu')
return 0;
}
Expand Down

0 comments on commit c0dd63a

Please sign in to comment.