Skip to content

Commit

Permalink
Correccion de errores
Browse files Browse the repository at this point in the history
  • Loading branch information
UO285267 committed Mar 10, 2024
1 parent ad25dbb commit 22b6ab6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
30 changes: 15 additions & 15 deletions webapp/src/components/QuizGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
8 changes: 3 additions & 5 deletions webapp/src/components/login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 22b6ab6

Please sign in to comment.