From 482e890d95e403e9e768fa1248d385e25bb0fdff Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Fri, 27 Aug 2021 09:30:35 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Refactoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/actions/airdcpp.actions.tsx | 44 ++++------------------ src/client/components/AcquisitionPanel.tsx | 11 +++--- src/client/reducers/airdcpp.reducer.ts | 7 ++-- 3 files changed, 16 insertions(+), 46 deletions(-) diff --git a/src/client/actions/airdcpp.actions.tsx b/src/client/actions/airdcpp.actions.tsx index 54e7e06..e10a623 100644 --- a/src/client/actions/airdcpp.actions.tsx +++ b/src/client/actions/airdcpp.actions.tsx @@ -33,34 +33,6 @@ export const search = (data: SearchData) => async (dispatch) => { } const instance: SearchInstance = await SocketService.post("search"); - // We want to get notified about every new result in order to make the user experience better - await SocketService.addListener( - `search/${instance.id}`, - "search_result_added", - (groupedResult) => { - dispatch({ - type: AIRDCPP_SEARCH_RESULTS_RECEIVED, - groupedResult: groupedResult.result, - }); - // ...add the received result in the UI - // (it's probably a good idea to have some kind of throttling for the UI updates as there can be thousands of results) - }, - ); - - // We also want to update the existing items in our list when new hits arrive for the previously listed files/directories - await SocketService.addListener( - `search/${instance.id}`, - "search_result_updated", - async (groupedResult) => { - console.log(groupedResult); - dispatch({ - type: AIRDCPP_SEARCH_RESULTS_RECEIVED, - results: groupedResult, - }); - // ...update properties of the existing result in the UI - }, - ); - await SocketService.addListener( `search/${instance.id}`, "search_hub_searches_sent", @@ -90,15 +62,15 @@ export const search = (data: SearchData) => async (dispatch) => { data, ); - // await sleep(10000); - // const results = await SocketService.get( - // `search/${instance.id}/results/0/25`, - // ); + await sleep(10000); + const results = await SocketService.get( + `search/${instance.id}/results/0/125`, + ); - // dispatch({ - // type: AIRDCPP_SEARCH_RESULTS_RECEIVED, - // results, - // }); + dispatch({ + type: AIRDCPP_SEARCH_RESULTS_RECEIVED, + results, + }); } catch (error) { console.log("ERO", error); throw error; diff --git a/src/client/components/AcquisitionPanel.tsx b/src/client/components/AcquisitionPanel.tsx index f709ff8..732c7d7 100644 --- a/src/client/components/AcquisitionPanel.tsx +++ b/src/client/components/AcquisitionPanel.tsx @@ -15,9 +15,9 @@ export const AcquisitionPanel = ( props.comicBookMetadata.sourcedMetadata.comicvine.volumeInformation.name; const sanitizedVolumeName = volumeName.replace(/[^a-zA-Z0-9 ]/g, ""); const issueName = props.comicBookMetadata.sourcedMetadata.comicvine.name; - const airDCPPSearchResults = useSelector( - (state: RootState) => { console.log(state); return state.airdcpp.results;} - ); + const airDCPPSearchResults = useSelector((state: RootState) => { + return state.airdcpp.searchResults; + }); const isAirDCPPSearchInProgress = useSelector( (state: RootState) => state.airdcpp.isAirDCPPSearchInProgress, ); @@ -104,8 +104,7 @@ export const AcquisitionPanel = ( {/* AirDC++ results */}
- ASDASD {JSON.stringify(airDCPPSearchResults)} - {/* {!isNil(airDCPPSearchResults) && ( + {!isNil(airDCPPSearchResults) && ( @@ -172,7 +171,7 @@ export const AcquisitionPanel = ( })}
- )} */} + )}
); diff --git a/src/client/reducers/airdcpp.reducer.ts b/src/client/reducers/airdcpp.reducer.ts index 8ce47b2..a75ec8c 100644 --- a/src/client/reducers/airdcpp.reducer.ts +++ b/src/client/reducers/airdcpp.reducer.ts @@ -9,22 +9,21 @@ import { import { LOCATION_CHANGE } from "connected-react-router"; const initialState = { + searchResults: [], isAirDCPPSearchInProgress: false, searchInfo: null, searchInstance: null, downloadResult: null, bundleDBImportResult: null, - searchResults: [], }; function airdcppReducer(state = initialState, action) { switch (action.type) { case AIRDCPP_SEARCH_RESULTS_RECEIVED: - console.log("mad", state.searchResults); return { ...state, - isAirDCPPSearchInProgress: true, - searchResults: [...state.searchResults, action.groupedResult], + searchResults: action.results, + isAirDCPPSearchInProgress: false, }; case AIRDCPP_SEARCH_IN_PROGRESS: return {