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 T2Table from "../shared/T2Table"; import { useDispatch, useSelector } from "react-redux"; import { searchIssue } from "../../actions/fileops.actions"; import ellipsize from "ellipsize"; 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: 15, from: 0, }, type: "all", trigger: "libraryPage" }, ), ); }, []); // 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 = useMemo(() => [ { 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"; }, }, ], } ], []); /** * 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: "all", trigger: "libraryPage", }, ), ); }, []); /** * 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: "all", trigger: "libraryPage" }, ), ); }, []); // ImportStatus.propTypes = { // value: PropTypes.bool.isRequired, // }; return (

Library

{!isUndefined(searchResults.hits) && (
)}
); }; export default Library;