import React, { useCallback, ReactElement, useState } from "react"; import { isNil, isEmpty } from "lodash"; import { IExtractedComicBookCoverFile, RootState } from "threetwo-ui-typings"; import { importToDB } from "../../actions/fileops.actions"; import { comicinfoAPICall } from "../../actions/comicinfo.actions"; import { search } from "../../services/api/SearchApi"; import { Form, Field } from "react-final-form"; import Card from "../shared/Carda"; import ellipsize from "ellipsize"; import { convert } from "html-to-text"; import dayjs from "dayjs"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { COMICVINE_SERVICE_URI, LIBRARY_SERVICE_BASE_URI, } from "../../constants/endpoints"; import axios from "axios"; interface ISearchProps {} export const Search = ({}: ISearchProps): ReactElement => { const formData = { search: "", }; const queryClient = useQueryClient(); const [searchQuery, setSearchQuery] = useState(""); const [comicVineMetadata, setComicVineMetadata] = useState({}); const getCVSearchResults = (searchQuery) => { setSearchQuery(searchQuery.search); // queryClient.invalidateQueries({ queryKey: ["comicvineSearchResults"] }); }; const { data: comicVineSearchResults, isLoading, isSuccess, } = useQuery({ queryFn: async () => await axios({ url: `${COMICVINE_SERVICE_URI}/search`, method: "GET", params: { api_key: "a5fa0663683df8145a85d694b5da4b87e1c92c69", query: searchQuery, format: "json", limit: "10", offset: "0", field_list: "id,name,deck,api_detail_url,image,description,volume,cover_date", resources: "issue", }, }), queryKey: ["comicvineSearchResults", searchQuery], enabled: !isNil(searchQuery), }); // add to library const { data: additionResult } = useQuery({ queryFn: async () => await axios({ url: `${LIBRARY_SERVICE_BASE_URI}/rawImportToDb`, method: "POST", data: { importType: "new", payload: { rawFileDetails: { name: "", }, importStatus: { isImported: true, tagged: false, matchedResult: { score: "0", }, }, sourcedMetadata: { comicvine: comicVineMetadata?.comicData } || null, acquisition: { source: { wanted: true, name: "comicvine" } }, }, }, }), queryKey: ["additionResult"], enabled: !isNil(comicVineMetadata.comicData), }); const addToLibrary = (sourceName: string, comicData) => setComicVineMetadata({ sourceName, comicData }); const createDescriptionMarkup = (html) => { return { __html: html }; }; return (

Search

Browse your comic book collection.

(
{({ input, meta }) => { return ( ); }}
)} />
{!isNil(comicVineSearchResults?.data.results) && !isEmpty(comicVineSearchResults?.data.results) ? (
{comicVineSearchResults.data.results.map((result) => { return isSuccess ? (
{!isEmpty(result.volume.name) ? ( result.volume.name ) : ( No Name )}
Cover date {dayjs(result.cover_date).format("MMM D, YYYY")}
{result.id}
{result.api_detail_url}

{ellipsize( convert(result.description, { baseElements: { selectors: ["p", "div"], }, }), 320, )}

) : (
Loading
); })}
) : (

Search the ComicVine database

Note that you need an instance of AirDC++ already running to use this form to connect to it.

Search and add issues, series and trade paperbacks to your library. Then, download them using the configured AirDC++ or torrent clients.

)}
); }; export default Search;