From 9bbf2efc3c7bf62509b025c493cccb22dd5c5f75 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Thu, 18 Aug 2022 00:10:31 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=A2=20Unwrangling=20state=20vars=20for?= =?UTF-8?q?=20global=20search=20vs=20local?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/actions/fileops.actions.tsx | 38 ++++++++++++++----- .../components/GlobalSearchBar/SearchBar.tsx | 1 + .../components/Library/LibraryContainer.tsx | 3 +- .../components/WantedComics/WantedComics.tsx | 3 +- src/client/reducers/fileops.reducer.ts | 18 ++++++++- src/client/services/DcppSearchService.ts | 1 - 6 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/client/actions/fileops.actions.tsx b/src/client/actions/fileops.actions.tsx index 505dfd6..7c80ec7 100644 --- a/src/client/actions/fileops.actions.tsx +++ b/src/client/actions/fileops.actions.tsx @@ -31,6 +31,7 @@ import { LS_TOGGLE_IMPORT_QUEUE, SS_SEARCH_FAILED, SS_SEARCH_RESULTS_FETCHED_SPECIAL, + WANTED_COMICS_FETCHED, } from "../constants/action-types"; import { success } from "react-notification-system-redux"; import { removeLeadingPeriod } from "../shared/utils/formatting.utils"; @@ -288,21 +289,40 @@ export const searchIssue = (query, options) => async (dispatch) => { method: "POST", data: { ...query, ...options }, }); - console.log("options", options); + if (response.data.code === 404) { dispatch({ type: SS_SEARCH_FAILED, data: response.data, }); } - dispatch({ - type: SS_SEARCH_RESULTS_FETCHED, - data: response.data.body, - }); - dispatch({ - type: SS_SEARCH_RESULTS_FETCHED_SPECIAL, - data: response.data.body, - }); + + switch (options.trigger) { + case "wantedComicsPage": + dispatch({ + type: WANTED_COMICS_FETCHED, + data: response.data.body, + }); + break; + case "globalSearchBar": + dispatch({ + type: SS_SEARCH_RESULTS_FETCHED_SPECIAL, + data: response.data.body, + }); + break; + + case "libraryPage": + dispatch({ + type: SS_SEARCH_RESULTS_FETCHED, + data: response.data.body, + }); + break; + + default: + break; + } + + }; export const analyzeImage = (imageFilePath: string | Buffer) => async (dispatch) => { diff --git a/src/client/components/GlobalSearchBar/SearchBar.tsx b/src/client/components/GlobalSearchBar/SearchBar.tsx index 5092e7c..958b091 100644 --- a/src/client/components/GlobalSearchBar/SearchBar.tsx +++ b/src/client/components/GlobalSearchBar/SearchBar.tsx @@ -31,6 +31,7 @@ export const SearchBar = (data: ISearchBarProps): ReactElement => { from: 0, }, type: "volumeName", + trigger: "globalSearchBar" }, ), ); diff --git a/src/client/components/Library/LibraryContainer.tsx b/src/client/components/Library/LibraryContainer.tsx index 48c8edd..07bb2c5 100644 --- a/src/client/components/Library/LibraryContainer.tsx +++ b/src/client/components/Library/LibraryContainer.tsx @@ -18,13 +18,14 @@ const LibraryContainer = (): ReactElement => { from: 0, }, type: "all", + trigger: "libraryPage" }, ), ); }, []); const searchResults = useSelector( - (state: RootState) => state.fileOps.librarySearchResults, + (state: RootState) => state.fileOps.libraryComics, ); const searchError = useSelector( (state: RootState) => state.fileOps.librarySearchError, diff --git a/src/client/components/WantedComics/WantedComics.tsx b/src/client/components/WantedComics/WantedComics.tsx index 3743138..9d720fa 100644 --- a/src/client/components/WantedComics/WantedComics.tsx +++ b/src/client/components/WantedComics/WantedComics.tsx @@ -8,7 +8,7 @@ import MetadataPanel from "../shared/MetadataPanel"; export const WantedComics = (props): ReactElement => { const wantedComics = useSelector( - (state: RootState) => state.fileOps.librarySearchResultsFormatted, + (state: RootState) => state.fileOps.wantedComics, ); const dispatch = useDispatch(); useEffect(() => { @@ -23,6 +23,7 @@ export const WantedComics = (props): ReactElement => { from: 0, }, type: "wanted", + trigger: "wantedComicsPage" }, ), ); diff --git a/src/client/reducers/fileops.reducer.ts b/src/client/reducers/fileops.reducer.ts index dd41111..0cc0619 100644 --- a/src/client/reducers/fileops.reducer.ts +++ b/src/client/reducers/fileops.reducer.ts @@ -44,7 +44,7 @@ const initialState = { extractedComicBookArchive: [], recentComics: [], wantedComics: [], - librarySearchResults: [], + libraryComics: [], librarySearchResultsFormatted: [], librarySearchResultCount: 0, libraryQueueResults: [], @@ -190,12 +190,13 @@ function fileOpsReducer(state = initialState, action) { case SS_SEARCH_RESULTS_FETCHED: { return { ...state, - librarySearchResults: action.data, + libraryComics: action.data, SSCallInProgress: false, }; } case SS_SEARCH_RESULTS_FETCHED_SPECIAL: { const foo = []; + console.log(action.data.hits) if (!isUndefined(action.data.hits)) { map(action.data.hits.hits, ({ _source }) => { foo.push(_source); @@ -207,6 +208,19 @@ function fileOpsReducer(state = initialState, action) { SSCallInProgress: false, }; } + case WANTED_COMICS_FETCHED: { + const foo = []; + if (!isUndefined(action.data.hits)) { + map(action.data.hits.hits, ({ _source }) => { + foo.push(_source); + }); + } + return { + ...state, + wantedComics: foo, + SSCallInProgress: false, + }; + } case SS_SEARCH_FAILED: { return { diff --git a/src/client/services/DcppSearchService.ts b/src/client/services/DcppSearchService.ts index 3aa1441..f7b7845 100644 --- a/src/client/services/DcppSearchService.ts +++ b/src/client/services/DcppSearchService.ts @@ -2,7 +2,6 @@ import { Socket } from "airdcpp-apisocket"; class AirDCPPSocket { constructor(configuration) { - console.log(configuration); let socketProtocol = ""; if (configuration.protocol === "https") { socketProtocol = "wss";