// @flow import React from 'react'; import classnames from 'classnames'; import Button from 'component/button'; import ClaimList from 'component/claimList'; import Paginate from 'component/common/paginate'; import Yrbl from 'component/yrbl'; const PAGE_SIZE = 10; type Props = { uris: Array, help: string, titleEmptyList: string, subtitleEmptyList: string, getActionButtons?: (url: string) => React$Node, className: ?string, }; export default function BlockList(props: Props) { const { uris: list, help, titleEmptyList, subtitleEmptyList, getActionButtons, className } = props; // Keep a local list to allow for undoing actions in this component const [localList, setLocalList] = React.useState(undefined); const stringifiedList = JSON.stringify(list); const hasLocalList = localList && localList.length > 0; const justBlocked = list && localList && localList.length < list.length; const [page, setPage] = React.useState(1); let totalPages = 0; let paginatedLocalList; if (localList) { paginatedLocalList = localList.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE); totalPages = Math.ceil(localList.length / PAGE_SIZE); } // ************************************************************************** // ************************************************************************** function getRenderActions() { if (getActionButtons) { return (claim) =>
{getActionButtons(claim.permanent_url)}
; } return undefined; } // ************************************************************************** // ************************************************************************** React.useEffect(() => { const list = stringifiedList && JSON.parse(stringifiedList); if (!hasLocalList) { setLocalList(list && list.length > 0 ? list : []); } }, [stringifiedList, hasLocalList]); React.useEffect(() => { if (justBlocked && stringifiedList) { setLocalList(JSON.parse(stringifiedList)); } }, [stringifiedList, justBlocked, setLocalList]); // ************************************************************************** // ************************************************************************** if (paginatedLocalList === undefined) { return null; } if (!hasLocalList) { return (
} /> ); } return ( <>
{help}
setPage(p)} /> ); }