diff --git a/src/client/actions/airdcpp.actions.tsx b/src/client/actions/airdcpp.actions.tsx index 7df2906..58a24a3 100644 --- a/src/client/actions/airdcpp.actions.tsx +++ b/src/client/actions/airdcpp.actions.tsx @@ -6,7 +6,8 @@ import { SearchResponse, } from "threetwo-ui-typings"; import { - AIRDCPP_SEARCH_RESULTS_RECEIVED, + AIRDCPP_SEARCH_RESULTS_ADDED, + AIRDCPP_SEARCH_RESULTS_UPDATED, AIRDCPP_HUB_SEARCHES_SENT, AIRDCPP_RESULT_DOWNLOAD_INITIATED, AIRDCPP_DOWNLOAD_PROGRESS_TICK, @@ -46,7 +47,7 @@ export const search = (data: SearchData) => async (dispatch) => { // (it's probably a good idea to have some kind of throttling for the UI updates as there can be thousands of results) dispatch({ - type: AIRDCPP_SEARCH_RESULTS_RECEIVED, + type: AIRDCPP_SEARCH_RESULTS_ADDED, groupedResult, }); }, @@ -60,7 +61,7 @@ export const search = (data: SearchData) => async (dispatch) => { async (groupedResult) => { // ...update properties of the existing result in the UI dispatch({ - type: AIRDCPP_SEARCH_RESULTS_RECEIVED, + type: AIRDCPP_SEARCH_RESULTS_UPDATED, groupedResult, }); }, diff --git a/src/client/constants/action-types.ts b/src/client/constants/action-types.ts index f5241dc..b6fef3e 100644 --- a/src/client/constants/action-types.ts +++ b/src/client/constants/action-types.ts @@ -38,9 +38,10 @@ export const IMS_COMIC_BOOK_GROUPS_CALL_IN_PROGRESS = export const IMS_COMIC_BOOK_GROUPS_CALL_FAILED = "IMS_COMIC_BOOK_GROUPS_CALL_FAILED"; +// AirDC++ export const AIRDCPP_SEARCH_IN_PROGRESS = "AIRDCPP_SEARCH_IN_PROGRESS"; -export const AIRDCPP_SEARCH_RESULTS_RECEIVED = - "AIRDCPP_SEARCH_RESULTS_RECEIVED"; +export const AIRDCPP_SEARCH_RESULTS_ADDED = "AIRDCPP_SEARCH_RESULTS_ADDED"; +export const AIRDCPP_SEARCH_RESULTS_UPDATED = "AIRDCPP_SEARCH_RESULTS_UPDATED"; export const AIRDCPP_SEARCH_COMPLETE = "AIRDCPP_SEARCH_COMPLETE"; export const AIRDCPP_HUB_SEARCHES_SENT = "AIRDCPP_HUB_SEARCHES_SENT"; diff --git a/src/client/reducers/airdcpp.reducer.ts b/src/client/reducers/airdcpp.reducer.ts index a7c245b..6dfb791 100644 --- a/src/client/reducers/airdcpp.reducer.ts +++ b/src/client/reducers/airdcpp.reducer.ts @@ -1,6 +1,7 @@ import { AIRDCPP_SEARCH_IN_PROGRESS, - AIRDCPP_SEARCH_RESULTS_RECEIVED, + AIRDCPP_SEARCH_RESULTS_ADDED, + AIRDCPP_SEARCH_RESULTS_UPDATED, AIRDCPP_HUB_SEARCHES_SENT, AIRDCPP_RESULT_DOWNLOAD_INITIATED, AIRDCPP_DOWNLOAD_PROGRESS_TICK, @@ -20,12 +21,23 @@ const initialState = { function airdcppReducer(state = initialState, action) { switch (action.type) { - case AIRDCPP_SEARCH_RESULTS_RECEIVED: + case AIRDCPP_SEARCH_RESULTS_ADDED: return { ...state, searchResults: [...state.searchResults, action.groupedResult], isAirDCPPSearchInProgress: true, }; + case AIRDCPP_SEARCH_RESULTS_UPDATED: + const bundleToUpdateIndex = state.searchResults.findIndex( + (bundle) => bundle.id === action.groupedResult.result.id, + ); + const updatedState = [...state.searchResults]; + updatedState[bundleToUpdateIndex] = action.groupedResult; + + return { + ...state, + searchResults: updatedState, + }; case AIRDCPP_SEARCH_IN_PROGRESS: return { ...state, diff --git a/src/client/shared/utils/tradepaperback.utils.ts b/src/client/shared/utils/tradepaperback.utils.ts index e569748..0a29f22 100644 --- a/src/client/shared/utils/tradepaperback.utils.ts +++ b/src/client/shared/utils/tradepaperback.utils.ts @@ -16,6 +16,6 @@ export const detectTradePaperbacks = (deck): any => { return item; } }); - console.log(compact(matches)); + // console.log(compact(matches)); return compact(matches); };