diff --git a/src/client/actions/fileops.actions.tsx b/src/client/actions/fileops.actions.tsx index da336e4..8d38b90 100644 --- a/src/client/actions/fileops.actions.tsx +++ b/src/client/actions/fileops.actions.tsx @@ -154,66 +154,58 @@ export const fetchVolumeGroups = () => (dispatch) => { }); } }; -export const fetchComicVineMatches = (searchPayload) => (dispatch) => { - try { - const issueString = searchPayload.rawFileDetails.name; - const issueSearchQuery: IComicVineSearchQuery = refineQuery(issueString); - let seriesSearchQuery: IComicVineSearchQuery = {} as IComicVineSearchQuery; - if (searchPayload.rawFileDetails.containedIn !== "comics") { - seriesSearchQuery = refineQuery( - searchPayload.rawFileDetails.containedIn.split("/").pop(), - ); - } +export const fetchComicVineMatches = + (searchPayload, issueSearchQuery, seriesSearchQuery?) => (dispatch) => { + try { + dispatch({ + type: CV_API_CALL_IN_PROGRESS, + }); - dispatch({ - type: CV_API_CALL_IN_PROGRESS, - }); - - axios - .request({ - url: `${COMICBOOKINFO_SERVICE_URI}/fetchresource`, - method: "POST", - data: { - format: "json", - sort: "name%3Aasc", - // hack - query: issueSearchQuery.searchParams.searchTerms.name - .replace(/[^a-zA-Z0-9 ]/g, "") - .trim(), - fieldList: "id", - limit: "20", - offset: "0", - resources: "issue", - scorerConfiguration: { - searchQuery: { + axios + .request({ + url: `${COMICBOOKINFO_SERVICE_URI}/fetchresource`, + method: "POST", + data: { + format: "json", + sort: "name%3Aasc", + // hack + query: issueSearchQuery.searchParams.searchTerms.name + .replace(/[^a-zA-Z0-9 ]/g, "") + .trim(), + fieldList: "id", + limit: "20", + offset: "0", + resources: "issue", + scorerConfiguration: { + searchQuery: { + issue: issueSearchQuery, + series: seriesSearchQuery, + }, + rawFileDetails: searchPayload.rawFileDetails, + }, + }, + transformResponse: (r) => { + const matches = JSON.parse(r); + return sortBy(matches, (match) => -match.score); + }, + }) + .then((response) => { + dispatch({ + type: CV_SEARCH_SUCCESS, + searchResults: response.data, + searchQueryObject: { issue: issueSearchQuery, series: seriesSearchQuery, }, - rawFileDetails: searchPayload.rawFileDetails, - }, - }, - transformResponse: (r) => { - const matches = JSON.parse(r); - return sortBy(matches, (match) => -match.score); - }, - }) - .then((response) => { - dispatch({ - type: CV_SEARCH_SUCCESS, - searchResults: response.data, - searchQueryObject: { - issue: issueSearchQuery, - series: seriesSearchQuery, - }, + }); }); - }); - /* return { issueSearchQuery, series: seriesSearchQuery.searchParams }; */ - } catch (error) { - console.log(error); - } + /* return { issueSearchQuery, series: seriesSearchQuery.searchParams }; */ + } catch (error) { + console.log(error); + } - dispatch({ - type: CV_CLEANUP, - }); -}; + dispatch({ + type: CV_CLEANUP, + }); + }; diff --git a/src/client/components/ComicDetail.tsx b/src/client/components/ComicDetail.tsx index e27c3f3..935563d 100644 --- a/src/client/components/ComicDetail.tsx +++ b/src/client/components/ComicDetail.tsx @@ -15,6 +15,7 @@ import { RawFileDetails } from "./ComicDetail/RawFileDetails"; import { ArchiveOperations } from "./ComicDetail/Tabs/ArchiveOperations"; import AcquisitionPanel from "./ComicDetail/AcquisitionPanel"; import DownloadsPanel from "./ComicDetail/DownloadsPanel"; +import { EditMetadataPanel } from "./ComicDetail/EditMetadataPanel"; import { Menu } from "./ComicDetail/ActionMenu/Menu"; import { isEmpty, isUndefined, isNil } from "lodash"; @@ -62,7 +63,6 @@ export const ComicDetail = ({}: ComicDetailProps): ReactElement => { const comicBookDetailData = useSelector( (state: RootState) => state.comicInfo.comicBookDetail, ); - const { comicObjectId } = useParams<{ comicObjectId: string }>(); const userSettings = useSelector((state: RootState) => state.settings.data); const { ADCPPSocket, setADCPPSocket } = useContext(AirDCPPSocketContext); @@ -75,7 +75,6 @@ export const ComicDetail = ({}: ComicDetailProps): ReactElement => { useEffect(() => { if (isEmpty(ADCPPSocket) && !isNil(userSettings.directConnect)) { - console.log(userSettings.directConnect.client.host.hostname); setADCPPSocket( new AirDCPPSocket({ protocol: `${userSettings.directConnect.client.host.protocol}`, @@ -118,10 +117,11 @@ export const ComicDetail = ({}: ComicDetailProps): ReactElement => { } }, }, - editComicArchive: { - content: () => <>, + editComicBookMetadata: { + content: () => , }, }; + console.log(comicVineSearchQueryObject); const [active, setActive] = useState(1); diff --git a/src/client/components/ComicDetail/ActionMenu/Menu.tsx b/src/client/components/ComicDetail/ActionMenu/Menu.tsx index 8a25b79..3d59c22 100644 --- a/src/client/components/ComicDetail/ActionMenu/Menu.tsx +++ b/src/client/components/ComicDetail/ActionMenu/Menu.tsx @@ -1,24 +1,44 @@ +import { filter, isEmpty, isNil, isUndefined } from "lodash"; import React, { ReactElement, useCallback } from "react"; import { useSelector, useDispatch } from "react-redux"; import Select, { components } from "react-select"; import { fetchComicVineMatches } from "../../../actions/fileops.actions"; +import { refineQuery } from "../../../shared/utils/filenameparser.utils"; export const Menu = (props): ReactElement => { const { data } = props; const { setSlidingPanelContentId, setVisible } = props.handlers; const dispatch = useDispatch(); const openDrawerWithCVMatches = useCallback(() => { - dispatch(fetchComicVineMatches(data)); + let seriesSearchQuery: IComicVineSearchQuery = {} as IComicVineSearchQuery; + let issueSearchQuery: IComicVineSearchQuery = {} as IComicVineSearchQuery; + + if (!isUndefined(data.rawFileDetails)) { + issueSearchQuery = refineQuery(data.rawFileDetails.name); + if (data.rawFileDetails.containedIn !== "comics") { + seriesSearchQuery = refineQuery( + data.rawFileDetails.containedIn.split("/").pop(), + ); + } + } else if (!isEmpty(data.sourcedMetadata)) { + issueSearchQuery = refineQuery(data.sourcedMetadata.comicvine.name); + } + + dispatch(fetchComicVineMatches(data, issueSearchQuery, seriesSearchQuery)); setSlidingPanelContentId("CVMatches"); setVisible(true); }, [dispatch, data]); + + const openEditMetadataPanel = useCallback(() => { + setSlidingPanelContentId("editComicBookMetadata"); + setVisible(true); + }, []); // Actions menu options and handler const CVMatchLabel = ( Match on ComicVine ); - const editLabel = ( Edit Metadata @@ -38,11 +58,20 @@ export const Menu = (props): ReactElement => { { value: "delete-comic", label: deleteLabel }, ]; + const filteredActionOptions = filter(actionOptions, (item) => { + if (isUndefined(data.rawFileDetails)) { + return item.value !== "match-on-comic-vine"; + } + return item; + }); const handleActionSelection = (action) => { switch (action.value) { case "match-on-comic-vine": openDrawerWithCVMatches(); break; + case "edit-metdata": + openEditMetadataPanel(); + break; default: console.log("No valid action selected."); break; @@ -61,7 +90,7 @@ export const Menu = (props): ReactElement => { } name="actions" isSearchable={false} - options={actionOptions} + options={filteredActionOptions} onChange={handleActionSelection} /> ); diff --git a/src/client/components/ComicDetail/ComicVineMatchPanel.tsx b/src/client/components/ComicDetail/ComicVineMatchPanel.tsx index b4e226b..9c1fe66 100644 --- a/src/client/components/ComicDetail/ComicVineMatchPanel.tsx +++ b/src/client/components/ComicDetail/ComicVineMatchPanel.tsx @@ -14,36 +14,38 @@ export const ComicVineMatchPanel = (comicVineData): ReactElement => { console.log(comicVineData); return ( <> -
-
- -

Searching against:

-
-
-
- Title - - { - comicVineSearchQueryObject.issue.searchParams.searchTerms - .name - } - + {!isEmpty(comicVineSearchQueryObject) && ( +
+
+ +

Searching against:

+
+
+
+ Title + + { + comicVineSearchQueryObject.issue.searchParams.searchTerms + .name + } + +
-
-
-
- Number - - { - comicVineSearchQueryObject.issue.searchParams.searchTerms - .number - } - +
+
+ Number + + { + comicVineSearchQueryObject.issue.searchParams.searchTerms + .number + } + +
-
+ )}
{!isEmpty(comicVineSearchResults) && ( - {!isNil(downloadProgressTick) ? ( - - ) : null} -
+
+ {!isNil(downloadProgressTick) ? ( + + ) : null} {!isEmpty(ADCPPSocket) ? ( ) : ( diff --git a/src/client/components/ComicDetail/EditMetadataPanel.tsx b/src/client/components/ComicDetail/EditMetadataPanel.tsx new file mode 100644 index 0000000..e59d05d --- /dev/null +++ b/src/client/components/ComicDetail/EditMetadataPanel.tsx @@ -0,0 +1,7 @@ +import React, { ReactElement } from "react"; + +export const EditMetadataPanel = (props): ReactElement => { + return <>adsasdasd; +}; + +export default EditMetadataPanel;