Skip to content

Commit

Permalink
Arreglo test
Browse files Browse the repository at this point in the history
  • Loading branch information
Verzidee committed Mar 25, 2024
1 parent 4adba80 commit d061806
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions webapp/src/components/pages/Jugar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 (
Expand Down

0 comments on commit d061806

Please sign in to comment.