import React, { useState, useMemo, useEffect } from "react"; import { Box, IconButton, List, ListItem, Pagination, Stack, Typography, Grid, Slide, Collapse, Grow, } from "@mui/material"; import { BasicDataItem, BasicDataViewProps } from "../../types/basicDataView"; import { SearchInput } from "../searchInput"; import Radio from "@mui/material/Radio"; import RadioGroup from "@mui/material/RadioGroup"; import FormControlLabel from "@mui/material/FormControlLabel"; import FormControl from "@mui/material/FormControl"; import FormLabel from "@mui/material/FormLabel"; import ClearIcon from "@mui/icons-material/Clear"; import { NixType, nixTypes } from "../../types/nix"; import { Filter } from "../searchInput/searchInput"; import { useRouter } from "next/router"; export type BasicListItem = { item: React.ReactNode; key: string; }; export type BasicListProps = BasicDataViewProps & { handleFilter: (filter: Filter | ((curr: Filter) => Filter)) => void; selected?: string | null; itemsPerPage: number; }; export function BasicList(props: BasicListProps) { const { items, pageCount = 1, itemsPerPage, handleSearch, handleFilter, selected = "", } = props; // const [from, setFrom] = useState("any"); // const [to, setTo] = useState("any"); const [page, setPage] = useState(1); const router = useRouter(); useEffect(() => { const { query } = router; if (query?.page) { if (typeof query.page === "string") { const page = Number(query.page); setPage(page); } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [router]); const pageItems = useMemo(() => { const startIdx = (page - 1) * itemsPerPage; const endIdx = page * itemsPerPage; return items.slice(startIdx, endIdx); }, [page, items, itemsPerPage]); const [searchTerm, setSearchTerm] = useState(""); const handlePageChange = ( _event: React.ChangeEvent, value: number ) => { setPage(value); }; const _handleFilter = (filter: Filter | ((curr: Filter) => Filter)) => { handleFilter(filter); setPage(1); }; const _handleSearch = (term: string) => { handleSearch && handleSearch(term); setSearchTerm(term); setPage(1); }; return ( _handleSearch("")} /> {pageItems.map(({ item, key }, idx) => ( {item} ))} ); }