import React, { ReactElement, useCallback, useEffect, useMemo } from "react"; import { useDispatch, useSelector } from "react-redux"; import { searchIssue } from "../../actions/fileops.actions"; import SearchBar from "../Library/SearchBar"; import T2Table from "../shared/T2Table"; import { isEmpty, isUndefined } from "lodash"; import MetadataPanel from "../shared/MetadataPanel"; export const WantedComics = (props): ReactElement => { const wantedComics = useSelector( (state: RootState) => state.fileOps.wantedComics, ); const dispatch = useDispatch(); useEffect(() => { dispatch( searchIssue( { query: {}, }, { pagination: { size: 25, from: 0, }, type: "wanted", trigger: "wantedComicsPage" }, ), ); }, []); const columnData = [ { header: "Comic Information", columns: [ { header: "Details", id: "comicDetails", minWidth: 350, accessorFn: data => data, cell: (value) => , }, ], }, { header: "Download Status", columns: [ { header: "Files", accessorKey: "acquisition", align: "right", cell: props => { const { directconnect: { downloads } } = props.getValue(); return (
{downloads.length > 0 ? ( {downloads.length} ) : null}
); }, }, { header: "Download Details", id: "downloadDetails", accessorKey: "acquisition", cell: data =>
    {data.getValue().directconnect.downloads.map(download => { return
  1. {download.name}
  2. ; })}
}, { header: "Type", id: "dcc", }, ], }, ]; /** * Pagination control that fetches the next x (pageSize) items * based on the y (pageIndex) offset from the Elasticsearch index * @param {number} pageIndex * @param {number} pageSize * @returns void * **/ const nextPage = useCallback((pageIndex: number, pageSize: number) => { dispatch( searchIssue( { query: {}, }, { pagination: { size: pageSize, from: pageSize * pageIndex + 1, }, type: "wanted", trigger: "wantedComicsPage", }, ), ); }, []); /** * Pagination control that fetches the previous x (pageSize) items * based on the y (pageIndex) offset from the Elasticsearch index * @param {number} pageIndex * @param {number} pageSize * @returns void **/ const previousPage = useCallback((pageIndex: number, pageSize: number) => { let from = 0; if (pageIndex === 2) { from = (pageIndex - 1) * pageSize + 2 - 17; } else { from = (pageIndex - 1) * pageSize + 2 - 16; } dispatch( searchIssue( { query: {}, }, { pagination: { size: pageSize, from, }, type: "wanted", trigger: "wantedComicsPage" }, ), ); }, []); return (

Wanted Comics

{!isEmpty(wantedComics) && (
{/* pagination controls */}
)}
); }; export default WantedComics;