From 22b6ab60e2396ed294ab461d4f57a4f7451c6dd8 Mon Sep 17 00:00:00 2001 From: Felipe Garcia Date: Mon, 11 Mar 2024 00:23:28 +0100 Subject: [PATCH] Correccion de errores --- webapp/src/components/QuizGame.js | 30 ++++++++++++++-------------- webapp/src/components/login/Login.js | 8 +++----- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/webapp/src/components/QuizGame.js b/webapp/src/components/QuizGame.js index 509ad71d..8b64b4ab 100644 --- a/webapp/src/components/QuizGame.js +++ b/webapp/src/components/QuizGame.js @@ -27,36 +27,36 @@ const QuizGame = () => { const wrongImage = 'https://img.freepik.com/foto-gratis/signo-cruzado-incorrecto-o-negativo-negativo-eleccion-icono-simbolo-icono-ilustracion-aislado-sobre-fondo-rojo-3d-rendering_56104-1219.jpg?t=st=1710078617~exp=1710082217~hmac=a9dc243dfad6f2c548c66d6748c5aae79b5039b1b5763e34bce3e787114bc329&w=1380'; useEffect(() => { - if (!isToastVisible && questionsNumber <= numberOfQuestions) { + const generateQuestion = async () => { + try { + const response = await axios.get(`${apiEndpoint}/generate-question`); + setCurrentQuestion(response.data); + setError(null); + } catch (error) { + setError('Ha habido un error cargando las preguntas'); + } + }; + + if (!isToastVisible && questionsNumber <= numberOfQuestions) { generateQuestion(); setAnswerSelected(false); } - }, [questionsNumber, isToastVisible,generateQuestion]); - - const generateQuestion = async () => { - try { - const response = await axios.get(`${apiEndpoint}/generate-question`); - setCurrentQuestion(response.data); - setError(null); - } catch (error) { - setError('Ha habido un error cargando las preguntas'); - } - }; + }, [questionsNumber, isToastVisible, apiEndpoint]); const handleAnswer = (answer) => { const isCorrect = answer === currentQuestion.correctAnswer; setAnsweredQuestions(prev => [...prev, { question: currentQuestion, isCorrect }]); setSelectedAnswer({ answer, isCorrect }); setAnswerSelected(true); - let toastId; + if(isCorrect) { - toastId = toast.success('¡Respuesta correcta!', { + toast.success('¡Respuesta correcta!', { position: toast.POSITION.TOP_CENTER, onClose: () => setIsToastVisible(false) // Aquí es donde se añade el onClose }); console.log(answeredQuestions) } else { - toastId = toast.error('Respuesta incorrecta', { + toast.error('Respuesta incorrecta', { position: toast.POSITION.TOP_CENTER, onClose: () => setIsToastVisible(false) // Aquí es donde se añade el onClose }); diff --git a/webapp/src/components/login/Login.js b/webapp/src/components/login/Login.js index e11e3b88..89f77154 100644 --- a/webapp/src/components/login/Login.js +++ b/webapp/src/components/login/Login.js @@ -10,19 +10,17 @@ const Login = () => { const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loginSuccess, setLoginSuccess] = useState(false); - const [createdAt, setCreatedAt] = useState(''); + const [openSnackbar, setOpenSnackbar] = useState(false); const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; const loginUser = async () => { try { - const response = await axios.post(`${apiEndpoint}/login`, { username, password }); + await axios.post(`${apiEndpoint}/login`, { username, password }); // Extract data from the response - const { createdAt: userCreatedAt } = response.data; - - setCreatedAt(userCreatedAt); + setLoginSuccess(true); setOpenSnackbar(true);