Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mostrar usuarios registrados y paginación de tablas #133

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 44 additions & 19 deletions webapp/src/components/HistoricalData.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import axios from 'axios';
import React, { useState, useEffect} from 'react';
import { useNavigate} from 'react-router-dom';
import { Container, Button} from '@mui/material';
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Container, Button, TablePagination } from '@mui/material';
import './HistoricalData.css';

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

const [questionsHistory, setQuestionsHistory] = useState([]);
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(10);

const paginatedData = questionsHistory.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage);

const handleChangePage = (event, newPage) => {
setPage(newPage);
};

const handleChangeRowsPerPage = (event) => {
setRowsPerPage(parseInt(event.target.value, 10));
setPage(0);
};



useEffect(() => {
handleShowHistory();
Expand Down Expand Up @@ -42,27 +57,37 @@ const HistoricalData = () => {

</div>
<div>
<table>
<thead>
<tr>
<th title='pregunta'>Pregunta</th>
<th title='correcta'>Opción correcta</th>
<th title='incorrecta'>Opción incorrecta 1</th>
<th title='incorrecta'>Opción incorrecta 2</th>
<th title='incorrecta'>Opción incorrecta 3</th>
</tr>
</thead>
<tbody>
{questionsHistory.map((row, rowIndex) => (
<tr key={rowIndex}>
<TableContainer>
<Table sx={{ minWidth: 650 }} aria-label="customized table">
<TableHead>
<TableRow>
<TableCell>Pregunta</TableCell>
<TableCell>Opción correcta</TableCell>
<TableCell>Opción incorrecta 1</TableCell>
<TableCell>Opción incorrecta 2</TableCell>
<TableCell>Opción incorrecta 3</TableCell>
</TableRow>
</TableHead>
<TableBody>
{paginatedData.map((row, rowIndex) => (
<TableRow key={rowIndex}>
{row.map((cell, cellIndex) => (
<td key={cellIndex}>{cell}</td>
<TableCell key={cellIndex}>{cell}</TableCell>
))}
</tr>
</TableRow>
))}
</tbody>
</table>
</div>
</TableBody>
</Table>
</TableContainer>
<TablePagination
component="div"
count={questionsHistory.length}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handleChangePage}
onRowsPerPageChange={handleChangeRowsPerPage}
/>
</div>
</Container>

);
Expand Down