import {Grid, Pagination} from '@mui/material'; import * as React from 'react'; import Page from "./Page"; interface List { id: string; date: string; } export default function Pages({pages, url, removeUrl, csrf, passphrase, setPassphrase}) { const isPassphraseSet = passphrase !== null; const perPage = 3; const total = pages.length; const numberOfPage = Math.ceil(total/perPage); const [currentPage, setPage] = React.useState(1); const [listPages, setListPages] = React.useState(pages); const removePage = async (id) => { const formData = new FormData(); formData.set('_token', csrf); formData.set('_method', 'DELETE'); const response = await fetch(removeUrl.replace("replace_me", id), { method: 'POST', body: formData }); const json = await response.json(); if (json.success) { console.log(listPages.length); const newListPages = listPages.filter(function (value) { console.log(value.id); return value.id !== id; }); setListPages(newListPages); console.log(newListPages.length); console.log(listPages.length); updateListPages(newListPages.slice((currentPage - 1) * perPage, ((currentPage - 1) * perPage) + perPage).map(page => )); } } const [listPagesDisplayed, updateListPages] = React.useState(listPages.slice((currentPage-1) * perPage, ((currentPage-1) * perPage) + perPage ).map(page => )); const handlePageChange = (event: React.ChangeEvent, value: number) => { setPage(value); updateListPages(listPages.slice((value-1) * perPage, ((value-1) * perPage) + perPage).map(page => )); }; if (isPassphraseSet) { return (
{listPagesDisplayed}
); } return (
); }