Skip to content

Commit

Permalink
fixing e2e problems
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfdzs committed Mar 11, 2024
1 parent ab65c2b commit 4801b15
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
19 changes: 9 additions & 10 deletions webapp/src/components/GetQuestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { Container, Typography, Box, Button } from '@mui/material';
import './stylesheets/GetQuestionCss.css';
import { useLocation } from "react-router-dom";
import {useNavigate} from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";

const GetQuestion = () => {
//all the information about the question
const [question, setQuestion] = useState('');
const [correctAnswer, setCorrectAnswer] = useState('');
const [answersArray, setAnswersArray] = useState([]);
const [isReady, setIsReady] = useState(false);
const [error, setError] = useState('');
const [answerFeedback, setAnswerFeedback] = useState('');
const [nextQuestion, setNextQuestion] = useState(true);
const [timer, setTimer] = useState(15);
Expand Down Expand Up @@ -51,11 +49,10 @@ const GetQuestion = () => {
setIsReady(true);

} catch (error) {
//setError(error.response.data.error);
if (error.response) {
setError(error.response.data.error);
console.error(error.response.data.error);
} else {
setError(error.message);
console.error(error.message);
}
}
};
Expand All @@ -73,11 +70,12 @@ const GetQuestion = () => {
const saveHistorial = async (selectedAnswer, correct) => {

const username2 = username;
const response = await axios.post(`${apiEndpoint}/saveHistorial`, {question, answersArray, correctAnswer, selectedAnswer, correct, username2});
await axios.post(`${apiEndpoint}/saveHistorial`, {question, answersArray, correctAnswer, selectedAnswer, correct, username2});
}

useEffect(() => {
getQuestion();
// eslint-disable-next-line
}, []);

/**
Expand All @@ -89,11 +87,11 @@ const GetQuestion = () => {
const checkAnswer = (selectedAnswer) => {
//only executes the first time a button is clicked
var correct = false;
if(answerFeedback == ''){
if(selectedAnswer == correctAnswer){
if(answerFeedback === ''){
if(selectedAnswer === correctAnswer){
correct = true;
setAnswerFeedback("You have won! Congratulations!");
}else if(timer == 0){
}else if(timer === 0){
selectedAnswer = "Time out";
setAnswerFeedback("You lost! You didn't answer in time :(");
} else {
Expand Down Expand Up @@ -137,6 +135,7 @@ const GetQuestion = () => {
} else if (timer === 0 && nextQuestion) {
checkAnswer(null);
}
// eslint-disable-next-line
}, [isReady, timer, nextQuestion]);


Expand Down
6 changes: 2 additions & 4 deletions webapp/src/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const Home = () => {

const location = useLocation();
const { username, createdAt } = location.state || {};

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

function handleStartGame(){
// Lógica para iniciar la partida
Expand Down Expand Up @@ -48,9 +46,9 @@ const Home = () => {
<Typography component="p" variant="body1" sx={{ textAlign: 'center', marginTop: 2 }}>
Here you can start a new game or check your record.
</Typography>
<Typography component="p" variant="body1" sx={{ textAlign: 'center', marginTop: 2 }}>
{/*<Typography component="p" variant="body1" sx={{ textAlign: 'center', marginTop: 2 }}>
Your account was created on {new Date(createdAt).toLocaleDateString()}.
</Typography>
</Typography>*/}
<Stack spacing={2} sx={{ marginTop: 4 }}>

<Button variant="contained" color="primary" size="large" onClick={handleStartGame}>
Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/Record.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const Record = () => {

useEffect(() => {
getHistorialForLoggedUser();
// eslint-disable-next-line
}, []);

return (
Expand Down

0 comments on commit 4801b15

Please sign in to comment.