forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { Container, Button } from '@mui/material'; | ||
|
||
const ScoreBoard = () => { | ||
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; | ||
const navigate = useNavigate(); | ||
const [scoreboard, setScoreboard] = useState([]); | ||
|
||
useEffect(() => { | ||
loadScoreboard(); | ||
}, []); | ||
|
||
const loadScoreboard = async () => { | ||
try { | ||
const response = await axios.get(`${apiEndpoint}/getScoreBoard`); | ||
setScoreboard(response.data); | ||
} catch (error) { | ||
console.error('Error:', error); | ||
} | ||
}; | ||
const handlePreviousPage = async () => { | ||
let path = '/MainPage'; | ||
navigate(path); | ||
}; | ||
return ( | ||
<Container component="main" maxWidth="md" sx={{ marginTop: 4 }}> | ||
<Button variant="contained" color="primary" onClick={handlePreviousPage}> | ||
Página anterior | ||
</Button> | ||
<div> | ||
<h2>Tabla de Puntuaciones</h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Usuario</th> | ||
<th>Preguntas Totales Acertadas</th> | ||
<th>Preguntas Totales Falladas</th> | ||
<th>Puntos</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{scoreboard.map((user, index) => ( | ||
<tr key={index}> | ||
<td>{user.username}</td> | ||
<td>{user.totalCorrect}</td> | ||
<td>{user.totalIncorrect}</td> | ||
<td>{user.points}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default ScoreBoard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters