From 3bfba3696cc822323ce9802a4dd83e90cb77cb0b Mon Sep 17 00:00:00 2001 From: bidof Date: Tue, 9 Apr 2024 14:17:21 +0200 Subject: [PATCH] problemas de depencias de react en despliegue --- webapp/src/App.js | 1 - webapp/src/components/game/BasicGame.js | 5 ++--- webapp/src/components/game/Game.js | 13 ++++--------- webapp/src/components/game/timers/Timer.jsx | 7 ++++++- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/webapp/src/App.js b/webapp/src/App.js index 274cc5d3..a324b313 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -4,7 +4,6 @@ import AddUser from './components/adduser/AddUser'; import Login from './components/login/Login'; import { AuthProvider } from './components/authcontext'; import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; -import StartButton from './components/startbutton/StartButton'; import Game from './components/game/Game'; import Home from './components/home/Home'; import Footer from './components/footer/Footer'; diff --git a/webapp/src/components/game/BasicGame.js b/webapp/src/components/game/BasicGame.js index ed5435f4..431ff3f3 100644 --- a/webapp/src/components/game/BasicGame.js +++ b/webapp/src/components/game/BasicGame.js @@ -6,7 +6,6 @@ heredas y sobreescribes y list */ import GameMode from './gameModes/GameMode'; import Swal from 'sweetalert2'; -import { Redirect } from 'react-router-dom'; class BasicGame extends GameMode { constructor() { @@ -22,7 +21,7 @@ class BasicGame extends GameMode { } async fetchQuestions() { - if(this.idioma == null) + if(this.idioma === null || this.idioma === undefined) this.idioma = 'en'; try { const response = await fetch(`${this.apiEndpoint}/getQuestionModoBasico?idioma=${this.idioma}`); @@ -107,7 +106,7 @@ class BasicGame extends GameMode { } nextQuestion() { - if(this.questions.length == 0){ + if(this.questions.length === 0){ console.log("no se tiene seguiente preungta , el array es vaicio"); return; // Salir del método si no hay preguntas } diff --git a/webapp/src/components/game/Game.js b/webapp/src/components/game/Game.js index c8251fa1..c38bc4a8 100644 --- a/webapp/src/components/game/Game.js +++ b/webapp/src/components/game/Game.js @@ -1,14 +1,12 @@ import { QuestionArea } from './QuestionArea'; import { useEffect, useState, useRef } from 'react'; import {useNavigate} from 'react-router-dom'; -import { Spinner, Box, AlertDialog, AlertDialogBody, AlertDialogFooter, AlertDialogHeader, AlertDialogContent, AlertDialogOverlay, Button,Center } from "@chakra-ui/react"; +import { Spinner, Box} from "@chakra-ui/react"; import BasicGame from './BasicGame'; import { useTranslation } from 'react-i18next'; -const apiEndpoint = process.env.REACT_APP_API_URI ||'http://localhost:8000'; function Game({darkMode,gameMode=new BasicGame()}) { - const [isOpen, setIsOpen] = useState(false); const [correctAnswers, setCorrectAnswers] = useState(0); const [incorrectAnswers, setIncorrectAnswers] = useState(0); const [totalTime, setTotalTime] = useState(0); @@ -41,7 +39,7 @@ function Game({darkMode,gameMode=new BasicGame()}) { }; startGameAsync(); - }, []); + }, [i18n.language, navigate]);//<-cambiar el array de depencias error despliegue @@ -79,14 +77,11 @@ function Game({darkMode,gameMode=new BasicGame()}) { } - }, [correctAnswers, incorrectAnswers]); + }, [correctAnswers, incorrectAnswers,totalTime]);//<-cambiar el array de depencias error despliegue + - const onClose=()=>{ - setIsOpen(false); - navigate('/home'); - } const handleTimeout = () => { handleAnswerSelect(false); diff --git a/webapp/src/components/game/timers/Timer.jsx b/webapp/src/components/game/timers/Timer.jsx index 79242e9c..f6faa404 100644 --- a/webapp/src/components/game/timers/Timer.jsx +++ b/webapp/src/components/game/timers/Timer.jsx @@ -2,13 +2,18 @@ import React, { useEffect, useState, useRef } from 'react'; import { CircularProgress, CircularProgressLabel, useColorModeValue } from '@chakra-ui/react'; import { Box } from "@chakra-ui/react"; + +// Define `resetTimerFunction` or import it from another module +const resetTimerFunction = () => { + // Your code here + }; export const Timer = React.memo(({ onTimeout, timeout = 30000, resetTimer, darkMode,gameFinish }) => { const [progress, setProgress] = useState(100); // Inicia el progreso en 100% const intervalRef = useRef(null); useEffect(() => { resetTimer.current = resetTimerFunction; - }, []); + }, [resetTimer]);