Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arreglo generacion de preguntas #269

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ const Game = ({ username, totalQuestions, timeLimit }) => {
}
};

const obtenerPreguntaAleatoria = async () => {
try {
const response = await axios.get(`${apiEndpoint}/getRandomQuestionGenerator`);
setQuestion(response.data);
const respuestas = [...response.data.incorrectas, response.data.correcta];
setRespuestasAleatorias(respuestas.sort(() => Math.random() - 0.5).slice(0, 4)); // Mostrar solo 4 respuestas
} catch (error) {
console.error("Error al obtener la pregunta aleatoria", error);
setError('Error al obtener la pregunta aleatoria');
}
};

const handleButtonClick = async (respuestaSeleccionada, index) => {
if (!finished) {
if (selectedOption !== null) return; // Si ya se seleccionó una opción, no hacer nada
Expand All @@ -97,6 +109,7 @@ const Game = ({ username, totalQuestions, timeLimit }) => {

// Después de 3 segundos, restablecer la selección y pasar a la siguiente pregunta
setTimeout(() => {
obtenerPreguntaAleatoria();
setSelectedOption(null);
addGeneratedQuestionBody();
setNumberClics(numberClics + 1);
Expand Down