From 66ab7f8bec5ea6f28abdb6021f721132d7054c24 Mon Sep 17 00:00:00 2001 From: Raymond Debasa Peralta Date: Mon, 8 Apr 2024 14:45:52 +0200 Subject: [PATCH 1/3] menu de usuario desplegable --- webapp/src/components/HistoricalUserData.js | 52 ++++++++++++--------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/webapp/src/components/HistoricalUserData.js b/webapp/src/components/HistoricalUserData.js index 22e2695e..2251523f 100644 --- a/webapp/src/components/HistoricalUserData.js +++ b/webapp/src/components/HistoricalUserData.js @@ -8,37 +8,45 @@ const HistoricalUserData = () => { const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; const [gameHistory, setGameHistory] = useState([]); - + const [expandedRows, setExpandedRows] = useState([]); const handleLoadHistory = async () => { try { const username = localStorage.getItem('username'); - const response = await axios.get(`${apiEndpoint}/getgamehistory/${username}`); + const response = await axios.get(`${apiEndpoint}/getgamehistory/${username}`); - // Ordenar la lista de historial de partidas por fecha (de más reciente a más antigua) - const sortedHistory = response.data.sort((a, b) => new Date(b.date) - new Date(a.date)); - - setGameHistory(sortedHistory); - - console.log("el historial actual es "+gameHistory); + // Ordenar la lista de historial de partidas por fecha (de más reciente a más antigua) + const sortedHistory = response.data.sort((a, b) => new Date(b.date) - new Date(a.date)); + setGameHistory(sortedHistory); } catch (error) { console.error('Error:', error); } }; - const handlePreviousPage = async () => { - let path= '/MainPage'; - navigate(path); - } + const handlePreviousPage = async () => { + let path = '/MainPage'; + navigate(path); + }; + const toggleRow = (index) => { + const newExpandedRows = [...expandedRows]; + if (newExpandedRows.includes(index)) { + // Si la fila ya está expandida, la contraemos + newExpandedRows.splice(newExpandedRows.indexOf(index), 1); + } else { + // Si la fila no está expandida, la expandimos + newExpandedRows.push(index); + } + setExpandedRows(newExpandedRows); + }; return ( - - + + @@ -56,9 +64,9 @@ const HistoricalUserData = () => { - {gameHistory.map((game) => ( + {gameHistory.map((game, index) => ( - + toggleRow(index)}> {game.date} {game.duration} {game.percentage}% @@ -66,10 +74,10 @@ const HistoricalUserData = () => { {game.correctAnswers} {game.incorrectAnswers} - {game.questions && game.questions.map((question, index) => ( - + {expandedRows.includes(index) && game.questions && game.questions.map((question, qIndex) => ( + -

Pregunta {index + 1}: {question.question}

+

Pregunta {qIndex + 1}: {question.question}

Respuesta Correcta: {question.correctAnswer}

Respuesta del Usuario: {question.userAnswer}

La respuesta fue: {question.correctAnswer === question.userAnswer ? 'Correcta' : 'Incorrecta'}

@@ -83,7 +91,7 @@ const HistoricalUserData = () => {
); - + }; export default HistoricalUserData; From a3bb07f88fee7d1b21f47fc359c7561fb29c18a2 Mon Sep 17 00:00:00 2001 From: Raymond Debasa Peralta Date: Mon, 15 Apr 2024 11:18:41 +0200 Subject: [PATCH 2/3] LogOut terminado --- webapp/src/components/Navbar.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/Navbar.js b/webapp/src/components/Navbar.js index 661a54dd..013ab731 100644 --- a/webapp/src/components/Navbar.js +++ b/webapp/src/components/Navbar.js @@ -1,14 +1,20 @@ import React, { useState } from 'react'; -import { Link } from 'react-router-dom'; +import { Link ,useNavigate} from 'react-router-dom'; import './Navbar.css'; const Navbar = () => { const [historialDropdownOpen, setHistorialDropdownOpen] = useState(false); - + const navigate = useNavigate(); const toggleHistorialDropdown = () => { setHistorialDropdownOpen(!historialDropdownOpen); }; + const handleLogout = () => { + localStorage.removeItem('username'); + navigate("/"); // Redirige a la página de inicio de sesión + }; + + return (