From d2873893b836d262181b6e6292ae94f7d588597b Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Tue, 2 Jan 2024 16:01:54 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20Refactored=20the=20scor?= =?UTF-8?q?ed=20matches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ComicDetail/ComicDetail.tsx | 7 +++--- .../components/ComicDetail/MatchResult.tsx | 22 ++++++++++++++--- src/client/components/Library/Library.tsx | 24 +++++++++++++++++-- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/client/components/ComicDetail/ComicDetail.tsx b/src/client/components/ComicDetail/ComicDetail.tsx index 31c9ffb..d2db27c 100644 --- a/src/client/components/ComicDetail/ComicDetail.tsx +++ b/src/client/components/ComicDetail/ComicDetail.tsx @@ -162,7 +162,7 @@ export const ComicDetail = (data: ComicDetailProps): ReactElement => { scorerConfiguration: { searchParams: issueSearchQuery.inferredIssueDetails, }, - rawFileDetails: searchPayload.rawFileDetails, + rawFileDetails: searchPayload, }, transformResponse: (r) => { const matches = JSON.parse(r); @@ -181,7 +181,8 @@ export const ComicDetail = (data: ComicDetailProps): ReactElement => { } else { matches = response.data.map((match) => match); } - setComicVineMatches(matches); + const scoredMatches = matches.sort((a, b) => b.score - a.score); + setComicVineMatches(scoredMatches); }); } catch (err) { console.log(err); @@ -198,7 +199,7 @@ export const ComicDetail = (data: ComicDetailProps): ReactElement => { } else if (!isEmpty(comicvine)) { issueSearchQuery = refineQuery(comicvine.name); } - fetchComicVineMatches(data, issueSearchQuery, seriesSearchQuery); + fetchComicVineMatches(rawFileDetails, issueSearchQuery, seriesSearchQuery); setSlidingPanelContentId("CVMatches"); setVisible(true); }; diff --git a/src/client/components/ComicDetail/MatchResult.tsx b/src/client/components/ComicDetail/MatchResult.tsx index 07905b6..e8dfdf9 100644 --- a/src/client/components/ComicDetail/MatchResult.tsx +++ b/src/client/components/ComicDetail/MatchResult.tsx @@ -46,8 +46,24 @@ export const MatchResult = (props: MatchResultProps) => { onError={handleBrokenImage} /> -
- {match.name ?

{match.name}

: null} +
+
+ {match.name ? ( +

{match.name}

+ ) : null} + +
+ {/* score */} + + + + + + {parseInt(match.score, 10)} + + +
+
@@ -89,7 +105,7 @@ export const MatchResult = (props: MatchResultProps) => { {match.volumeInformation.results.count_of_issues}

- Publisher: + Published by{" "} {match.volumeInformation.results.publisher.name}

diff --git a/src/client/components/Library/Library.tsx b/src/client/components/Library/Library.tsx index 287c916..6d8f725 100644 --- a/src/client/components/Library/Library.tsx +++ b/src/client/components/Library/Library.tsx @@ -200,7 +200,17 @@ export const Library = (): ReactElement => { **/ const nextPage = (pageIndex: number, pageSize: number) => { if (!isPlaceholderData) { - setOffset(pageSize * pageIndex + 1); + queryClient.invalidateQueries({ queryKey: ["comics"] }); + setSearchQuery({ + query: {}, + pagination: { + size: 15, + from: pageSize * pageIndex + 1, + }, + type: "all", + trigger: "libraryPage", + }); + // setOffset(pageSize * pageIndex + 1); } }; @@ -218,7 +228,17 @@ export const Library = (): ReactElement => { } else { from = (pageIndex - 1) * pageSize + 2 - (pageSize + 1); } - setOffset(from); + queryClient.invalidateQueries({ queryKey: ["comics"] }); + setSearchQuery({ + query: {}, + pagination: { + size: 15, + from, + }, + type: "all", + trigger: "libraryPage", + }); + // setOffset(from); }; // ImportStatus.propTypes = {