diff --git a/webapp/src/App.js b/webapp/src/App.js index d932005b..ff205fa2 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -16,12 +16,15 @@ function App() { return ( + Welcome to the 2024 edition of the Software Architecture course + {showLogin ? : } + - {showLogin ? ( + {showLogin ? ( Don't have an account? Register here. diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js new file mode 100644 index 00000000..805880ab --- /dev/null +++ b/webapp/src/components/Game.js @@ -0,0 +1,42 @@ +import React, { useState } from 'react'; +import axios from 'axios'; +import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; + +const Game = () => { + /*const [username, setUsername] = useState(''); + 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 }); + + // Extract data from the response + const { createdAt: userCreatedAt } = response.data; + + setCreatedAt(userCreatedAt); + setLoginSuccess(true); + + setOpenSnackbar(true); + } catch (error) { + setError(error.response.data.error); + } + }; + + const handleCloseSnackbar = () => { + setOpenSnackbar(false); + };*/ + + return ( +
+

Esta sería la pagina del juego

+
+ ); +}; + +export default Game; \ No newline at end of file diff --git a/webapp/src/components/HistoricalData.js b/webapp/src/components/HistoricalData.js new file mode 100644 index 00000000..ffaccebb --- /dev/null +++ b/webapp/src/components/HistoricalData.js @@ -0,0 +1,14 @@ +import React, { useState } from 'react'; +import axios from 'axios'; +import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; + +const HistoricalData = () => { + + return ( +
+

Esta sería la pagina del historico de partidas

+
+ ); +}; + +export default HistoricalData; \ No newline at end of file diff --git a/webapp/src/components/Login.js b/webapp/src/components/Login.js index 0ad6268e..b46c92ec 100644 --- a/webapp/src/components/Login.js +++ b/webapp/src/components/Login.js @@ -2,6 +2,9 @@ import React, { useState } from 'react'; import axios from 'axios'; import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; +import Game from './Game'; +import HistoricalData from './HistoricalData'; +import App from '../App'; const Login = () => { const [username, setUsername] = useState(''); @@ -11,6 +14,10 @@ const Login = () => { const [createdAt, setCreatedAt] = useState(''); const [openSnackbar, setOpenSnackbar] = useState(false); + // Declara las variables (izquierda) y el metodo que la modifica (derecha). Se inicializa a false (useState) + const [showGame, setShowGame] = useState(false); + const [showHistoricalData, setShowHistoricaData] = useState(false); + const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; const loginUser = async () => { @@ -33,17 +40,43 @@ const Login = () => { setOpenSnackbar(false); }; + const handleShowGame = () => { + setShowGame(true); + }; + + const handleShowHistoricalData = () => { + setShowHistoricaData(true); + }; + return ( + {/* Los operadores logicos funcionan de la manera: + condicion ? (lo que se hace si se cumple) : (lo que se hace si no se cumple) */} {loginSuccess ? ( -
- - Hello {username}! - - - Your account was created on {new Date(createdAt).toLocaleDateString()}. - -
+ showGame || showHistoricalData ? ( + showGame ? ( + + ):( + + ) + ) : ( +
+ + Hello {username}! + + + Your account was created on {new Date(createdAt).toLocaleDateString()}. + + + {/* Se declaran los botones en los q al hacer click se ejecuta el metodo especificado en onClick*/} + + +
+ ) ) : (