Skip to content

Commit

Permalink
Merge pull request #260 from Arquisoft/dev
Browse files Browse the repository at this point in the history
Arreglos
  • Loading branch information
uo283055 authored Apr 11, 2024
2 parents 818df9e + ae886ed commit 42822f6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
47 changes: 25 additions & 22 deletions webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const Game = ({ username, totalQuestions, timeLimit }) => {

useEffect(() => {
obtenerPreguntaAleatoria();
}, [numberClics]);


}, [obtenerPreguntaAleatoria]);

useEffect(() => {
const interval = setInterval(() => {
Expand All @@ -34,7 +36,7 @@ const Game = ({ username, totalQuestions, timeLimit }) => {
}, 1000);

return () => clearInterval(interval);
}, [timer, finished]);
}, [timeLimit, timer, finished]);

const obtenerPreguntaAleatoria = async () => {
try {
Expand Down Expand Up @@ -64,6 +66,18 @@ const Game = ({ username, totalQuestions, timeLimit }) => {
return `${minsRStr}:${secsRStr}`;
}

const addGeneratedQuestionBody = async () => {
try {
await axios.post(`${apiEndpoint}/addGeneratedQuestion`, {
generatedQuestionBody: question.questionBody,
correctAnswer: question.correcta
});

} catch (error) {
setError(error.response.data.error);
}
};

const handleButtonClick = async (respuestaSeleccionada, index) => {
if (!finished) {
if (selectedOption !== null) return; // Si ya se seleccionó una opción, no hacer nada
Expand All @@ -76,6 +90,7 @@ const Game = ({ username, totalQuestions, timeLimit }) => {
} else {
setSelectedAnswer('incorrect');
}
console.log(`The selected answer is: ${selectedAnswer}`);

// Si ya llegamos a la última pregunta, acabamos la partida para que se muestre el resultado
if(numberClics===totalQuestions-1){
Expand All @@ -92,14 +107,6 @@ const Game = ({ username, totalQuestions, timeLimit }) => {
}
};

useEffect(() => {
if ((timer >= timeLimit || numberClics === totalQuestions - 1)&& !almacenado) {
addRecord();
updateRanking();
setAlmacenado(true);
}
}, [timer, numberClics, totalQuestions, timeLimit]);

const addRecord = async () => {
try {
await axios.post(`${apiEndpoint}/addRecord`, {
Expand All @@ -125,19 +132,15 @@ const Game = ({ username, totalQuestions, timeLimit }) => {
} catch (error) {
setError(error.response.data.error);
}
};

const addGeneratedQuestionBody = async () => {
try {
await axios.post(`${apiEndpoint}/addGeneratedQuestion`, {
generatedQuestionBody: question.questionBody,
correctAnswer: question.correcta
});

} catch (error) {
setError(error.response.data.error);
};

useEffect(() => {
if ((timer >= timeLimit || numberClics === totalQuestions - 1)&& !almacenado) {
addRecord();
updateRanking();
setAlmacenado(true);
}
};
}, [addRecord, updateRanking, timer, numberClics, totalQuestions, timeLimit, almacenado]);

if(isNaN(totalQuestions)){
totalQuestions=10;
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const Login = ({ setLogged }) => {

useEffect(() => {
calculateTotalTime();
}, [settings]);
}, [settings, calculateTotalTime]);

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/RankingList.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const RankingList = () => {
};

fetchUsers();
}, []);
}, [apiEndpoint]);

const sortedUsers = [...listUsers].sort((a, b) => {
if (sortColumn === 'username') {
Expand Down

0 comments on commit 42822f6

Please sign in to comment.