From d06180669079046b198bc9bb34602541adf29de7 Mon Sep 17 00:00:00 2001 From: Zohaib Akhtar Kausar Date: Mon, 25 Mar 2024 13:04:07 +0100 Subject: [PATCH] Arreglo test --- webapp/src/components/pages/Jugar.js | 59 ++++++++++++++-------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/webapp/src/components/pages/Jugar.js b/webapp/src/components/pages/Jugar.js index 86db3fc..8ccb8d6 100644 --- a/webapp/src/components/pages/Jugar.js +++ b/webapp/src/components/pages/Jugar.js @@ -54,34 +54,12 @@ function Jugar() { getQuestions(); } }, [isLoggedIn, navigate, getQuestions]); - - useEffect(() => { - if (!quizFinished && questionsLoaded) { - const countdown = setInterval(() => { - setTimer((prevTimer) => { - if (prevTimer === 1) { - handleNextQuestion(true); // Agrega un indicador de que el cambio fue por tiempo - return INITIAL_TIMER; - } - return prevTimer - 1; - }); - }, 1000); - return () => clearInterval(countdown); - } - }, [quizFinished, questionsLoaded, currentQuestionIndex, timer, handleNextQuestion]); - - const handleAnswerSelect = (index) => { - setSelectedAnswerIndex(index); - }; - - const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; - const handleNextQuestion = (timeExpired = false) => { setTimer(INITIAL_TIMER); if (selectedAnswerIndex !== null || timeExpired) { const isCorrect = - selectedAnswerIndex !== null && - questions[currentQuestionIndex].answers[selectedAnswerIndex]?.correct; + selectedAnswerIndex !== null && + questions[currentQuestionIndex].answers[selectedAnswerIndex]?.correct; if (isCorrect) { setCorrectAnswers(correctAnswers + 1); } @@ -99,14 +77,37 @@ function Jugar() { NumPreguntasJugadas: questions.length, // Número total de preguntas jugadas (la longitud de la matriz de preguntas) NumAcertadas: correctAnswers, // Número de preguntas respondidas correctamente }) - .then(response => { - console.log(response.data); // Mensaje de confirmación del servidor - }) - .catch(error => { - console.error('Error al guardar el historial:', error); + .then(response => { + console.log(response.data); // Mensaje de confirmación del servidor + }) + .catch(error => { + console.error('Error al guardar el historial:', error); + }); + } + }; + + useEffect(() => { + if (!quizFinished && questionsLoaded) { + const countdown = setInterval(() => { + setTimer((prevTimer) => { + if (prevTimer === 1) { + handleNextQuestion(true); // Agrega un indicador de que el cambio fue por tiempo + return INITIAL_TIMER; + } + return prevTimer - 1; }); + }, 1000); + return () => clearInterval(countdown); } + }, [quizFinished, questionsLoaded, currentQuestionIndex, timer, handleNextQuestion]); + + const handleAnswerSelect = (index) => { + setSelectedAnswerIndex(index); }; + + const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; + + const videoSource = quizFinished ? "/videos/celebracion.mp4" : "/videos/question.mp4"; // Renderizado del componente return (