import React, { useMemo, ReactElement, useCallback, useEffect } from "react"; import PropTypes from "prop-types"; import { useNavigate } from "react-router-dom"; import { isEmpty, isNil, isUndefined } from "lodash"; import MetadataPanel from "../shared/MetadataPanel"; import SearchBar from "./SearchBar"; import { useDispatch, useSelector } from "react-redux"; import { searchIssue } from "../../actions/fileops.actions"; import ellipsize from "ellipsize"; import { ColumnDef, flexRender, getCoreRowModel, getFilteredRowModel, useReactTable, PaginationState, } from "@tanstack/react-table"; export const Library = (): ReactElement => { const searchResults = useSelector( (state: RootState) => state.fileOps.libraryComics, ); const searchError = useSelector( (state: RootState) => state.fileOps.librarySearchError, ); const dispatch = useDispatch(); useEffect(() => { dispatch( searchIssue( { query: {}, }, { pagination: { size: 25, from: 0, }, type: "all", trigger: "libraryPage" }, ), ); }, []); const T2Table = (tableOptions): ReactElement => { const { columns, totalPages, rowClickHandler } = tableOptions; // pagination methods const goToNextPage = useCallback((pageIndex, pageSize) => { dispatch( searchIssue( { query: {}, }, { pagination: { size: pageSize, from: pageSize * pageIndex + 1, }, type: "all", trigger: "libraryPage", }, ), ); }, []); const goToPreviousPage = useCallback((pageIndex, pageSize) => { let from = 0; if (pageIndex === 2) { from = (pageIndex - 1) * pageSize + 2 - 27; } else { from = (pageIndex - 1) * pageSize + 2 - 26; } dispatch( searchIssue( { query: {}, }, { pagination: { size: pageSize, from, }, type: "all", trigger: "libraryPage" }, ), ); }, []); const table = useReactTable({ data: searchResults.hits.hits, columns, manualPagination: true, getCoreRowModel: getCoreRowModel(), getFilteredRowModel: getFilteredRowModel(), pageCount: totalPages, // getPaginationRowModel: getPaginationRowModel(), debugTable: true, }); return ( <> {table.getHeaderGroups().map((headerGroup, idx) => ( {headerGroup.headers.map((header, idx) => ( ))} ))} {table.getRowModel().rows.map((row, idx) => { return ( rowClickHandler(row)} > {row.getVisibleCells().map(cell => ( ))} ); })}
{header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext() )}
{flexRender(cell.column.columnDef.cell, cell.getContext())}
{/* pagination control */} ); }; // programatically navigate to comic detail const navigate = useNavigate(); const navigateToComicDetail = (row) => { navigate(`/comic/details/${row.original._id}`); }; const ComicInfoXML = (value) => { return value.data ? (
Series {ellipsize(value.data.series[0], 25)}
Pages {value.data.pagecount[0]}
Issue {!isNil(value.data.number) && ( {parseInt(value.data.number[0], 10)} )}
) : null; }; const WantedStatus = ({ value }) => { return !value ? Wanted : null; }; const columns = [ { header: "Comic Metadata", footer: 1, columns: [ { header: "File Details", id: "fileDetails", minWidth: 400, accessorKey: "_source", cell: info => { return ; }, }, { header: "ComicInfo.xml", accessorKey: "_source.sourcedMetadata.comicInfo", align: "center", minWidth: 250, cell: info => !isEmpty(info.getValue()) ? ( ) : ( No ComicInfo.xml ), }, ], }, { header: "Additional Metadata", columns: [ { header: "Publisher", accessorKey: "_source.sourcedMetadata.comicvine.volumeInformation", cell: info => { return ( !isNil(info.getValue()) && (
{info.getValue().publisher.name}
) ); }, }, { header: "Something", accessorKey: "_source.acquisition.source.wanted", cell: info => { !isUndefined(info.getValue()) ? : "Nothing"; }, }, ], } ] // ImportStatus.propTypes = { // value: PropTypes.bool.isRequired, // }; return (

Library

{/* Search bar */}
{!isUndefined(searchResults.hits) && (
{/* pagination controls */}
)}
); }; export default Library;