Skip to content

Commit

Permalink
Merge pull request #122 from Arquisoft/Marina
Browse files Browse the repository at this point in the history
Añadir botón para salir de la partida.
  • Loading branch information
UO288559 authored Apr 15, 2024
2 parents 0aff471 + 9de0dfd commit a767826
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
10 changes: 10 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ app.get('/endgamestats', async (req, res) => {
}
});

app.get('/restartGame', async (req, res) => {
try {
const URL = generatorUrl + '/restartGame';
const response = await axios.get(URL);
res.json(response.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

// Read the OpenAPI YAML file synchronously
// Hubo que cambiar el path porque los test e2e ahora sólo se ejecutan desde webapp
openapiPath='../gatewayservice/openapi.yaml'
Expand Down
10 changes: 10 additions & 0 deletions questiongenerator/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,15 @@ app.get('/updateQuestion', async (req, res) => {
}
});

app.get('/restartGame', async (req,res) => {
try{
numberOfQuestions = 0;
res.status(200).json({ message: "Número de preguntas actualizado", numberOfQuestions });
}catch (error){
res.status(400).json({ error: error.message });
}

});


module.exports = server
47 changes: 47 additions & 0 deletions webapp/src/components/fragments/NavigationBar_Game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, {useCallback, useState} from 'react';
import { useNavigate, useLocation } from 'react-router-dom';
import { AppBar, Button, Grid } from '@mui/material';
import { useUser } from '../UserContext';
import axios from 'axios';

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';
const NavigationBar_Game = () => {

const [error, setError] = useState('');
const { usernameGlobal, setUsernameGlobal } = useUser();
const navigate = useNavigate();

const location = useLocation();

const isHiddenRoute = location.pathname !== '/Game' ;


const showHome = useCallback(async () => {
try {
axios.get(`${apiEndpoint}/restartGame`);
navigate("/PantallaInicio")
} catch (error) {
console.log("Error: " + error.response.data.error);
setError(error.response.data.error);
}
})

if (isHiddenRoute) {
return null; // Si no estás en / o /App, no muestra la barra de navegación
}

return (
<AppBar position="fixed" sx={{ backgroundColor: '#9A77B0' }}>
<Grid container justifyContent="space-between">
{/* Columna izquierda */}
<Grid item>
<Button variant="contained" color="inherit" style={{ background: '#9A77B0', border: 'none', padding: 0, marginRight: '10px', marginLeft: '10px'}} onClick={showHome}>
<img src={require('../images/home.png')} style={{ width: '50px', height: '50px' }} alt="Imagen home"/>
</Button>
</Grid>
</Grid>
</AppBar>
);
};

export default NavigationBar_Game;
10 changes: 4 additions & 6 deletions webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import NavigationBar from './components/fragments/NavigationBar';
import NavigationBar_Game from './components/fragments/NavigationBar_Game';
import reportWebVitals from './reportWebVitals';
import { UserProvider } from './components/UserContext';

Expand All @@ -18,16 +20,14 @@ import Game from './components/Game';
import Gamehistory from './components/Gamehistory';
import Ranking from './components/Ranking';
import GameConfiguration from './components/GameConfiguration';
import EndGame from './components/EndGame';
import Footer from './components/fragments/Footer';
import NavigationBar from './components/fragments/NavigationBar';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<UserProvider>
<Router>
<NavigationBar />
<NavigationBar />
<NavigationBar_Game/>
<Routes>
<Route path="/" element={<App/>}></Route>
<Route path="/PantallaInicio" element={<PantallaInicio/>}></Route>
Expand All @@ -38,9 +38,7 @@ root.render(
<Route path="/Gamehistory" element={<Gamehistory />} />
<Route path="/Ranking" element={<Ranking />} />
<Route path="/GameConfiguration" element={<GameConfiguration />} />
<Route path="/EndGame" element={<EndGame />} />
</Routes>
<Footer />
</Router>
</UserProvider>
</React.StrictMode>
Expand Down

0 comments on commit a767826

Please sign in to comment.