diff --git a/src/client/components/Library.tsx b/src/client/components/Library.tsx index f6e88ea..7cf303a 100644 --- a/src/client/components/Library.tsx +++ b/src/client/components/Library.tsx @@ -1,20 +1,13 @@ import React, { useState, useEffect, useMemo, ReactElement } from "react"; import PropTypes from "prop-types"; import { useHistory } from "react-router"; -import { - removeLeadingPeriod, - escapePoundSymbol, -} from "../shared/utils/formatting.utils"; import { useTable, usePagination } from "react-table"; -import prettyBytes from "pretty-bytes"; -import styled from "styled-components"; -import ellipsize from "ellipsize"; import { useDispatch, useSelector } from "react-redux"; -import { Form, Field } from "react-final-form"; import { getComicBooks } from "../actions/fileops.actions"; -import { isNil } from "lodash"; -import { IMPORT_SERVICE_HOST } from "../constants/endpoints"; -import { Link } from "react-router-dom"; +import { isEmpty, isNil } from "lodash"; +import { RawFileDetails } from "./Library/RawFileDetails"; +import { ComicVineDetails } from "./Library/ComicVineDetails"; +import { SearchBar } from "./Library/SearchBar"; interface IComicBookLibraryProps { matches?: unknown; @@ -38,79 +31,7 @@ export const Library = ({}: IComicBookLibraryProps): ReactElement => { const navigateToComicDetail = (id) => { history.push(`/comic/details/${id}`); }; - // raw file details - const RawFileDetails = ({ value }) => { - if (!isNil(value.path)) { - const encodedFilePath = encodeURI( - `${IMPORT_SERVICE_HOST}/${value.cover.filePath}`, - ); - const filePath = escapePoundSymbol(encodedFilePath); - return ( -
-
-
-
-
- -
-
-
    -
  • - {ellipsize(value.name, 18)} -
  • -
  • -
    -
    - - {value.extension} - - - {prettyBytes(value.fileSize)} - -
    -
    -
  • -
-
-
-
- ); - } else if (!isNil(value.comicvine)) { - return ( -
-
-
-
-
- -
-
-
    -
  • - {ellipsize(value.name, 18)} -
  • -
  • -
    -
    - - ComicVine ID - - - {value.comicvine.id} - -
    -
    -
  • -
-
-
-
- ); - } - }; + const ImportStatus = ({ value }) => { return value ? ( Imported @@ -119,53 +40,6 @@ export const Library = ({}: IComicBookLibraryProps): ReactElement => { ); }; - const foo = () => {}; - const SearchBar = () => { - return ( -
-
( -
- - - {({ input, meta }) => { - return ( - - ); - }} - -
- )} - /> -
-
-

- -

-

- -

-
-
-
- ); - }; const columns = useMemo( () => [ { @@ -178,7 +52,16 @@ export const Library = ({}: IComicBookLibraryProps): ReactElement => { !isNil(row.rawFileDetails) ? row.rawFileDetails : row.sourcedMetadata, - Cell: RawFileDetails, + Cell: ({ value }) => { + // If no CV info available, use raw file metadata + if (!isNil(value.cover)) { + return ; + } + // If CV metadata available, show it + if (!isNil(value.comicvine)) { + return ; + } + }, }, { Header: "Import Status", @@ -255,18 +138,6 @@ export const Library = ({}: IComicBookLibraryProps): ReactElement => { [], ); - RawFileDetails.propTypes = { - value: PropTypes.shape({ - cover: PropTypes.shape({ - filePath: PropTypes.string, - }), - name: PropTypes.string, - path: PropTypes.string, - fileSize: PropTypes.number, - extension: PropTypes.string, - }), - }; - ImportStatus.propTypes = { value: PropTypes.bool.isRequired, }; diff --git a/src/client/components/Library/ComicVineDetails.tsx b/src/client/components/Library/ComicVineDetails.tsx new file mode 100644 index 0000000..be88bf6 --- /dev/null +++ b/src/client/components/Library/ComicVineDetails.tsx @@ -0,0 +1,37 @@ +import React, { ReactElement } from "react"; +import PropTypes from "prop-types"; +import ellipsize from "ellipsize"; + +export const ComicVineDetails = (comicVineData): ReactElement => { + const { data } = comicVineData; + return ( +
+
+
+
+
+ +
+
+
    +
  • + {ellipsize(data.name, 18)} +
  • +
  • +
    +
    + ComicVine ID + + {data.comicvine.id} + +
    +
    +
  • +
+
+
+
+ ); +}; + +export default ComicVineDetails; diff --git a/src/client/components/Library/RawFileDetails.tsx b/src/client/components/Library/RawFileDetails.tsx new file mode 100644 index 0000000..dd79591 --- /dev/null +++ b/src/client/components/Library/RawFileDetails.tsx @@ -0,0 +1,59 @@ +import React, { ReactElement } from "react"; +import PropTypes from "prop-types"; +import { escapePoundSymbol } from "../../shared/utils/formatting.utils"; +import prettyBytes from "pretty-bytes"; +import ellipsize from "ellipsize"; +import { IMPORT_SERVICE_HOST } from "../../constants/endpoints"; + +// raw file details +export const RawFileDetails = (rawFileData): ReactElement => { + const { data } = rawFileData; + const encodedFilePath = encodeURI( + `${IMPORT_SERVICE_HOST}/${data.cover.filePath}`, + ); + const filePath = escapePoundSymbol(encodedFilePath); + return ( +
+
+
+
+
+ +
+
+
    +
  • + {ellipsize(data.name, 18)} +
  • +
  • +
    +
    + + {data.extension} + + + {prettyBytes(data.fileSize)} + +
    +
    +
  • +
+
+
+
+ ); +}; + +export default RawFileDetails; + +RawFileDetails.propTypes = { + data: PropTypes.shape({ + cover: PropTypes.shape({ + filePath: PropTypes.string, + }), + name: PropTypes.string, + path: PropTypes.string, + fileSize: PropTypes.number, + extension: PropTypes.string, + }), +}; diff --git a/src/client/components/Library/SearchBar.tsx b/src/client/components/Library/SearchBar.tsx new file mode 100644 index 0000000..b1e28d2 --- /dev/null +++ b/src/client/components/Library/SearchBar.tsx @@ -0,0 +1,54 @@ +import React, { ReactElement } from "react"; +import PropTypes from "prop-types"; +import { Form, Field } from "react-final-form"; +import { Link } from "react-router-dom"; + +export const SearchBar = (): ReactElement => { + const foo = () => {}; + return ( +
+ ( +
+ + + {({ input, meta }) => { + return ( + + ); + }} + +
+ )} + /> +
+
+

+ +

+

+ +

+
+
+
+ ); +}; + +export default SearchBar; diff --git a/src/client/components/RecentlyImported.tsx b/src/client/components/RecentlyImported.tsx index b34fddf..a02e487 100644 --- a/src/client/components/RecentlyImported.tsx +++ b/src/client/components/RecentlyImported.tsx @@ -45,7 +45,7 @@ export const RecentlyImported = ({ ); imagePath = escapePoundSymbol(encodedFilePath); comicName = rawFileDetails.name; - } else if (!isNil(sourcedMetadata)) { + } else if (!isNil(sourcedMetadata.comicvine)) { imagePath = sourcedMetadata.comicvine.image.small_url; comicName = sourcedMetadata.comicvine.name; }