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

Webapp interface #55

Merged
merged 40 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7f0c9b0
Primera version del un ejemplo con una pregunta y añadida un poco de …
alegarman2002 Feb 24, 2024
588cc02
Añadido un contador de tiempo visual
alegarman2002 Feb 24, 2024
ff3891c
Commit antes de una probable explosion
alegarman2002 Feb 24, 2024
3c528d9
Intento numero 1 de aprobar
alegarman2002 Feb 24, 2024
a7d17d1
Merge branch 'documentation_alejandro_liliana' of https://github.com/…
alegarman2002 Feb 24, 2024
e2e6f3b
Corrección documentación
uo288574 Feb 26, 2024
494e137
imagen arbol actualizada
uo288574 Mar 1, 2024
b52653e
cambio documentación apartado 10
uo288574 Mar 1, 2024
1fc1f56
Fixed problem with buttons
alegarman2002 Mar 2, 2024
44d032d
Merge branch 'documentation_alejandro_liliana' of https://github.com/…
alegarman2002 Mar 2, 2024
1913b0d
Merge branch 'documentation_alejandro_liliana' into webapp_interface
alegarman2002 Mar 2, 2024
7923846
Merge branch 'service_question_generator' into webapp_interface
alegarman2002 Mar 2, 2024
301be1a
First try to connect to questiongenerator api
alegarman2002 Mar 4, 2024
b76de84
Added the menu with navigation
alegarman2002 Mar 5, 2024
472649b
Merge branch 'service_question_generator' into webapp_interface
AbelMH1 Mar 9, 2024
48caf3d
Merge branch 'service_question_generator' into webapp_interface
AbelMH1 Mar 9, 2024
3dc210a
Removed unnecesary line
AbelMH1 Mar 9, 2024
67d4aad
Added query params (hardcoded) and fixed question display
AbelMH1 Mar 9, 2024
cac634d
barra de navegación y pie de página
uo288574 Mar 11, 2024
4396167
change check answers
uo288574 Mar 12, 2024
420ef2b
Merge branch 'service_question_generator' into webapp_interface
alegarman2002 Mar 13, 2024
b3f302a
Updated the game so we can have unlimited questions
alegarman2002 Mar 13, 2024
559b223
Fixed problem of dependencies
alegarman2002 Mar 13, 2024
a0c33a7
Fixed problem with login test apparently
alegarman2002 Mar 13, 2024
cc0cf88
Added the login into the inder for navigation
alegarman2002 Mar 13, 2024
c5681f2
Fixed problems witho second part of text at login and problems with a…
alegarman2002 Mar 13, 2024
ecd16b9
Trying to fix error on how we call th context.js
alegarman2002 Mar 13, 2024
6b1ecae
Fixed Login test, tryung to fix app test
alegarman2002 Mar 13, 2024
d7a0a7a
Return to the previous version of app test
alegarman2002 Mar 13, 2024
4ca2be4
Trying to fix the app text with an update on the index
alegarman2002 Mar 13, 2024
df1e22f
Making the test a bit more simple
alegarman2002 Mar 13, 2024
80cbfe1
Trying to fix again the app text pls kill me
alegarman2002 Mar 13, 2024
d43156c
Eliminated unussed resources for that moment
alegarman2002 Mar 13, 2024
e5b6677
First try in test for firstGame
alegarman2002 Mar 13, 2024
cd1e826
Desisto de hacer los test de momento
alegarman2002 Mar 13, 2024
85108d2
Booro los archivos
alegarman2002 Mar 13, 2024
951564a
sonarcloud problem solved (??)
uo288574 Mar 13, 2024
ff89910
sonarcloud problem solved at menu
uo288574 Mar 13, 2024
7ac26cd
Merge branch 'develop' into webapp_interface
AbelMH1 Mar 13, 2024
38ada23
Eliminated the unnecessary files
alegarman2002 Mar 13, 2024
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
Binary file modified docs/images/QualityTree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/src/10_quality_requirements.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ occurs.
|The user must correctly answer questions on different topics. This will improve the user experience and maintain the interest of the participants.
|High

|Integrity
|Fiability
|The game must be played without errors.
|The answer determined as correct for each question by the system shall be the one that is actually correct.
|Medium
Expand Down
1 change: 1 addition & 0 deletions questionsservice/questiongeneratorservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"homepage": "https://github.com/arquisoft/wiq_es6c#readme",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.2",
"axios": "^1.6.5",
"cors": "^2.8.5",
Expand Down
88 changes: 88 additions & 0 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.2",
"axios": "^1.6.5",
"fetch": "^1.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.1",
"react-circular-progressbar": "^2.1.0",
"react-scripts": "5.0.1",
"web-vitals": "^3.5.1"
},
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function App() {
<Container component="main" maxWidth="xs">
<CssBaseline />
<Typography component="h1" variant="h5" align="center" sx={{ marginTop: 2 }}>
Welcome to wiq_0
Welcome to wiq_06c
</Typography>
{showLogin ? <Login /> : <AddUser />}
<Typography component="div" align="center" sx={{ marginTop: 2 }}>
Expand Down
11 changes: 10 additions & 1 deletion webapp/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { render, screen } from '@testing-library/react';
import App from './App';
import { ContextFun } from './components/Context';
import { BrowserRouter as Router } from 'react-router-dom';


test('renders learn react link', () => {
render(<App />);
render(
<ContextFun>
<Router>
<App />
</Router>
</ContextFun>
);
const linkElement = screen.getByText(/Welcome to wiq_0/i);
expect(linkElement).toBeInTheDocument();
});
17 changes: 17 additions & 0 deletions webapp/src/components/Context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { createContext, useContext, useState } from 'react';

const Context = createContext();

export function ContextFun({ children }) {
const [usernameGlobal, setUsernameGlobal] = useState('');

return (
<Context.Provider value={{ usernameGlobal, setUsernameGlobal }}>
{children}
</Context.Provider>
);
}

export function useUser() {
return useContext(Context);
}
41 changes: 41 additions & 0 deletions webapp/src/components/FirstGame.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
button {
font-size: 20px;
width: 200px;
height: 50px;
justify-content: center;
margin-bottom: 15px;
}

.questionStructure .answers {
display: flex;
justify-content: center; /* Alinea los elementos en el centro horizontal /
align-items: center; / Alinea los elementos en el centro vertical /
height: 100vh; / Ajusta la altura al 100% del viewport */
}

.allAnswers {
width:100%;
display: block;
}

.asnwers {
width:100%;
}
.progressBar {
height: 100%;
margin-top: 10;
width:10%;
display: inline-block;
}

.question {
height: 100%;
width: 90%;
display: inline-block;
}

.questionText {
display: flex;
margin-bottom: 25px;

}
130 changes: 130 additions & 0 deletions webapp/src/components/FirstGame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import React, { useState, useEffect } from 'react';
import { Container, Typography } from '@mui/material';
import './FirstGame.css';
import { CircularProgressbar } from 'react-circular-progressbar';
import 'react-circular-progressbar/dist/styles.css';
import axios from 'axios';
import { json } from 'react-router-dom';
import { useLocation } from 'react-router-dom';

const apiEndpoint = 'http://localhost:8007';
const Quiz = () => {
var questions = useLocation().state.questions;

const [currentQuestionIndex, setCurrentQuestionIndex] = React.useState(0);
const [selectedOption, setSelectedOption] = React.useState(null);
const [isCorrect, setIsCorrect] = React.useState(null);

const esperar = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
};

function secureRandomNumber(max) {
const randomBytes = new Uint32Array(1);
window.crypto.getRandomValues(randomBytes);
return randomBytes[0] % max;
}

function shuffleArray(array) {
// Crea una copia del array original
const shuffledArray = [...array];

// Recorre el array desde el último elemento hasta el primero
for (let i = shuffledArray.length - 1; i > 0; i--) {
// Genera un índice aleatorio entre 0 y el índice actual
//const randomIndex = Math.floor(Math.random() * (i + 1));
const randomIndex = secureRandomNumber(i + 1);

// Intercambia el elemento actual con el elemento del índice aleatorio
const temp = shuffledArray[i];
shuffledArray[i] = shuffledArray[randomIndex];
shuffledArray[randomIndex] = temp;
}

// Devuelve el array barajado
return shuffledArray;
}


const getQuestions = async () => {
try {
const response = await axios.get(`${apiEndpoint}/questions?n_preguntas=${1}`);
console.log(response.data.length)
for (var i = 0; i < response.data.length; i++) {
var possibleAnswers = [response.data[i].respuesta_correcta, response.data[i].respuestas_incorrectas[0], response.data[i].respuestas_incorrectas[1], response.data[i].respuestas_incorrectas[2]]
possibleAnswers = shuffleArray(possibleAnswers)
questions.push({
question: response.data[i].pregunta,
options: possibleAnswers,
correctAnswer: response.data[i].respuesta_correcta
})
}
} catch (error) {
console.error(error);
}
console.log(questions)
};

const checkAnswer = async (option) => {
getQuestions()
setIsCorrect(option === questions[currentQuestionIndex].correctAnswer);
setSelectedOption(option);

const botonIncorrecta = document.getElementById('option-' + questions[currentQuestionIndex].options.indexOf(option))
if (!isCorrect) {
botonIncorrecta.style.backgroundColor = 'red'
}

const numberAnswer = questions[currentQuestionIndex].options.indexOf(questions[currentQuestionIndex].correctAnswer)
const botonCorrecta = document.getElementById('option-' + numberAnswer)
botonCorrecta.style.backgroundColor = 'green'
// Pasar a la siguiente pregunta después de responder

await esperar(2000); // Espera 2000 milisegundos (2 segundos)
botonIncorrecta.style.backgroundColor = 'lightgrey'
botonCorrecta.style.backgroundColor = 'lightgrey'
if (questions.length-1 !== currentQuestionIndex) {
setCurrentQuestionIndex((prevIndex) => prevIndex + 1);
}
setIsCorrect(false)


};

return (
<Container component="main" maxWidth="xl" sx={{ marginTop: 4 }}>
<div className="questionStructure">
<div class="question">
<Typography class="questionText" component="h1" variant="h5" sx={{ textAlign: 'center' }}>
{questions[currentQuestionIndex].question}
</Typography>
</div>

<div class="progressBar">
{/* {MiCircularProgressbar} */}
</div>
<div class="allAnswers">
{questions[currentQuestionIndex].options.map((option, index) => (
<div key={index} className="answers">
<button
id={`option-${index}`}
name="quiz"
value={option}
onClick={() => checkAnswer(option)}
style={{backgroundColor: 'lightgrey'}}
>
{option}
</button>
</div>
)
)}
</div>
</div>
{/* {isCorrect !== null && (
<p>{isCorrect ? '¡Respuesta correcta!' : 'Respuesta incorrecta.'}</p>
)} */}
</Container>
);
};

export default Quiz;
Loading