import React, { JSXElementConstructor, useEffect } from 'react' import { any } from '@xrengine/engine/src/common/functions/MatchesUtils' import { State, useHookstate } from '@xrengine/hyperflux' import { Grid, Stack } from '@mui/material' import { Button } from '../inputs/Button' import Well from './Well' export default function PaginatedList({ list, element, options }: { ['list']: T[] | State ['element']: (index: T | State) => JSX.Element ['options']?: { ['countPerPage']?: number } }) { const countPerPage = options?.countPerPage ?? 7 const currentPage = useHookstate(0) function getPageIndices() { const start = countPerPage * currentPage.value return [start, Math.min(start + countPerPage, list.length /*- 1*/)] } const pageView = useHookstate(getPageIndices()) useEffect(() => { pageView.set(getPageIndices()) }, [currentPage]) return ( <> {[-2, -1, 0, 1, 2].map((idx) => { const btnKey = `paginatedButton-${idx}` if (!(currentPage.value + idx < 0 || currentPage.value + idx >= list.length / countPerPage)) return ( ) else return (

ยท

) })}
{(pageView.value[0] === pageView.value[1] ? list : list.slice(...pageView.value)).map((index) => { return element(index) })} ) }