Skip to content

Commit

Permalink
Pruebas (nada de código definitivo) ajustes temáticas
Browse files Browse the repository at this point in the history
  • Loading branch information
uo287627 committed Apr 11, 2024
1 parent 3bcdd43 commit 0f863ac
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 64 deletions.
11 changes: 6 additions & 5 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ app.post('/adduser', async (req, res) => {

app.post('/addRecord', async(req, res) => {
try{
const recordResponse = await axios.post(recordServiceUrl+'/addRecord', req.body);
const recordResponse = await axios.post(recordServiceUrl+'/addRecord', req.body);
res.json(recordResponse.data);
}catch (error){
Expand Down Expand Up @@ -261,7 +262,7 @@ app.get('/getRandomQuestionGenerator', async (req, res) => {
});

//TEMATICAS
app.get('/getRandomQuestionDeporte', async (req, res) => {
app.get('/getRandomQuestionSports', async (req, res) => {
try {
const questionGeneratorResponse = await axios.get(`${questiongeneratorservice}/getRandomQuestionDeporte`);
res.json(questionGeneratorResponse.data);
Expand All @@ -274,7 +275,7 @@ app.get('/getRandomQuestionDeporte', async (req, res) => {
}
});

app.get('/getRandomQuestionAnio', async (req, res) => {
app.get('/getRandomQuestionImportantDates', async (req, res) => {
try {
const questionGeneratorResponse = await axios.get(`${questiongeneratorservice}/getRandomQuestionAnio`);
res.json(questionGeneratorResponse.data);
Expand All @@ -287,7 +288,7 @@ app.get('/getRandomQuestionAnio', async (req, res) => {
}
});

app.get('/getRandomQuestionMusica', async (req, res) => {
app.get('/getRandomQuestionMusic', async (req, res) => {
try {
const questionGeneratorResponse = await axios.get(`${questiongeneratorservice}/getRandomQuestionMusica`);
res.json(questionGeneratorResponse.data);
Expand All @@ -300,7 +301,7 @@ app.get('/getRandomQuestionMusica', async (req, res) => {
}
});

app.get('/getRandomQuestionLibro', async (req, res) => {
app.get('/getRandomQuestionLiterature', async (req, res) => {
try {
const questionGeneratorResponse = await axios.get(`${questiongeneratorservice}/getRandomQuestionLibro`);
res.json(questionGeneratorResponse.data);
Expand All @@ -313,7 +314,7 @@ app.get('/getRandomQuestionLibro', async (req, res) => {
}
});

app.get('/getRandomQuestionPaisYGeo', async (req, res) => {
app.get('/getRandomQuestionCountries', async (req, res) => {
try {
const questionGeneratorResponse = await axios.get(`${questiongeneratorservice}/getRandomQuestionPaisYGeo`);
res.json(questionGeneratorResponse.data);
Expand Down
42 changes: 33 additions & 9 deletions webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,26 @@ const Game = ({ username, totalQuestions, timeLimit, themes }) => {

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

if(isNaN(totalQuestions)){
totalQuestions=10;
}
if(isNaN(timeLimit)){
timeLimit=180;
}
if(themesSelected===undefined){
setThemesSelected({
Sports: true,
ImportantDates: true,
Music: true,
Literature: true,
Countries: true
});
}

useEffect(() => {
obtenerPreguntaAleatoria();
}, [numberClics]);

console.log(themesSelected);

useEffect(() => {
const interval = setInterval(() => {
if (timer>=timeLimit){
Expand All @@ -49,6 +63,23 @@ const Game = ({ username, totalQuestions, timeLimit, themes }) => {
console.error("Error al obtener la pregunta aleatoria", error);
setError('Error al obtener la pregunta aleatoria');
}

console.log("Antes: "+themesSelected);
// Generar array solo con los temas seleccionados
const temasSeleccionados = Object.entries(themesSelected)
.filter(([tema, seleccionado]) => seleccionado===true)
.map(([tema]) => tema);
console.log("Temas seleccionados : ", temasSeleccionados);

const temasSeleccionadoss = Object.entries(themesSelected)
.filter(([tema, seleccionado]) => seleccionado==true)
.map(([tema]) => tema);
console.log("Temas seleccionados 2: ", temasSeleccionadoss);

const temasSeleccionadosss = Object.entries(themesSelected)
.filter(([tema, seleccionado]) => seleccionado)
.map(([tema]) => tema);
console.log("Temas seleccionados 3: ", temasSeleccionadosss);
};

const handleTimeRemaining = () => {
Expand Down Expand Up @@ -142,13 +173,6 @@ const Game = ({ username, totalQuestions, timeLimit, themes }) => {
}
};

if(isNaN(totalQuestions)){
totalQuestions=10;
}
if(isNaN(timeLimit)){
timeLimit=180;
}

return (
<Container maxWidth="lg">
{numberClics >= totalQuestions || timer >= timeLimit ? (
Expand Down
105 changes: 55 additions & 50 deletions webapp/src/components/GameSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const GameSettings = ({ setSettings }) => {
const [themes, setThemes] = useState(() => {
const storedValue = localStorage.getItem('themes');
return storedValue ? JSON.parse(storedValue) : {
sports: true,
importantDates: true,
music: true,
literature: true,
countries: true
Sports: true,
ImportantDates: true,
Music: true,
Literature: true,
Countries: true
};
});

Expand Down Expand Up @@ -64,58 +64,63 @@ const GameSettings = ({ setSettings }) => {
localStorage.setItem('numberQuestions', numberQuestions);
localStorage.setItem('totalMins', totalMins);
localStorage.setItem('totalSecs', totalSecs);
localStorage.setItem('themes', JSON.stringify(themes));
localStorage.setItem('themes', themes);
setSettings({ numberQuestions, totalMins, totalSecs, themes });
}, [numberQuestions, totalMins, totalSecs, themes, setSettings]);

return (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<div style={{ display: 'flex', justifyContent: 'center', flexDirection:'column' }}>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Box sx={{ width: 300 }}>
<Typography variant="h6" gutterBottom>
Seleccione el número de preguntas:
</Typography>
<Slider
aria-label="Custom marks"
defaultValue={10}
value={numberQuestions}
onChange={handleQuestionsSlider}
step={5}
valueLabelDisplay="auto"
marks={markQuestions}
min={markQuestions[0].value}
max={markQuestions[markQuestions.length - 1].value}
/>
</Box>
<Box sx={{ width: 300 }}>
<Typography variant="h6" gutterBottom>
Seleccione el tiempo máximo de partida:
</Typography>
<TextField
label="Minutos:"
value={totalMins}
onChange={handleTimeTfMins}
type="number"
inputProps={{
min: 1,
max: 10,
step: 1,
}}
sx={{ marginBottom: '1rem', marginRight: '0.5rem', marginTop: '1rem' }}
/>
<TextField
label="Segundos:"
value={totalSecs}
onChange={handleTimeTfSecs}
type="number"
inputProps={{
min: 0,
max: 60,
step: 10,
}}
sx={{ marginBottom: '1rem', marginTop: '1rem' }}
/>
</Box>
</div>
<Box sx={{ width: 300 }}>
<Typography variant="h6" gutterBottom>
Seleccione el número de preguntas:
Seleccione las temáticas de las preguntas:
</Typography>
<Slider
aria-label="Custom marks"
defaultValue={10}
value={numberQuestions}
onChange={handleQuestionsSlider}
step={5}
valueLabelDisplay="auto"
marks={markQuestions}
min={markQuestions[0].value}
max={markQuestions[markQuestions.length - 1].value}
/>
</Box>
<Box sx={{ width: 300 }}>
<Typography variant="h6" gutterBottom>
Seleccione el tiempo máximo de partida:
</Typography>
<TextField
label="Minutos:"
value={totalMins}
onChange={handleTimeTfMins}
type="number"
inputProps={{
min: 1,
max: 10,
step: 1,
}}
sx={{ marginBottom: '1rem', marginRight: '0.5rem', marginTop: '1rem' }}
/>
<TextField
label="Segundos:"
value={totalSecs}
onChange={handleTimeTfSecs}
type="number"
inputProps={{
min: 0,
max: 60,
step: 10,
}}
sx={{ marginBottom: '1rem', marginTop: '1rem' }}
/>
</Box>
<Box sx={{ width: 300 }}>
<FormGroup>
<FormControlLabel control={<Checkbox name='sports' checked={themes.sports} onChange={handleThemes} />} label="Deportes" />
<FormControlLabel control={<Checkbox name='importantDates' checked={themes.importantDates} onChange={handleThemes} />} label="Fechas históricas" />
Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/#.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const Login = ({ setLogged }) => {
margin="normal"
fullWidth
label="Password"
label="Password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
Expand Down

0 comments on commit 0f863ac

Please # to comment.