🐞 Fixed a bug with search_results_updated listener for AirDC++

This commit is contained in:
2021-09-23 22:40:37 -07:00
parent 2ba6e23efa
commit 51e9397055
4 changed files with 22 additions and 8 deletions

View File

@@ -6,7 +6,8 @@ import {
SearchResponse, SearchResponse,
} from "threetwo-ui-typings"; } from "threetwo-ui-typings";
import { import {
AIRDCPP_SEARCH_RESULTS_RECEIVED, AIRDCPP_SEARCH_RESULTS_ADDED,
AIRDCPP_SEARCH_RESULTS_UPDATED,
AIRDCPP_HUB_SEARCHES_SENT, AIRDCPP_HUB_SEARCHES_SENT,
AIRDCPP_RESULT_DOWNLOAD_INITIATED, AIRDCPP_RESULT_DOWNLOAD_INITIATED,
AIRDCPP_DOWNLOAD_PROGRESS_TICK, 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) // (it's probably a good idea to have some kind of throttling for the UI updates as there can be thousands of results)
dispatch({ dispatch({
type: AIRDCPP_SEARCH_RESULTS_RECEIVED, type: AIRDCPP_SEARCH_RESULTS_ADDED,
groupedResult, groupedResult,
}); });
}, },
@@ -60,7 +61,7 @@ export const search = (data: SearchData) => async (dispatch) => {
async (groupedResult) => { async (groupedResult) => {
// ...update properties of the existing result in the UI // ...update properties of the existing result in the UI
dispatch({ dispatch({
type: AIRDCPP_SEARCH_RESULTS_RECEIVED, type: AIRDCPP_SEARCH_RESULTS_UPDATED,
groupedResult, groupedResult,
}); });
}, },

View File

@@ -38,9 +38,10 @@ export const IMS_COMIC_BOOK_GROUPS_CALL_IN_PROGRESS =
export const IMS_COMIC_BOOK_GROUPS_CALL_FAILED = export const IMS_COMIC_BOOK_GROUPS_CALL_FAILED =
"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_IN_PROGRESS = "AIRDCPP_SEARCH_IN_PROGRESS";
export const AIRDCPP_SEARCH_RESULTS_RECEIVED = export const AIRDCPP_SEARCH_RESULTS_ADDED = "AIRDCPP_SEARCH_RESULTS_ADDED";
"AIRDCPP_SEARCH_RESULTS_RECEIVED"; export const AIRDCPP_SEARCH_RESULTS_UPDATED = "AIRDCPP_SEARCH_RESULTS_UPDATED";
export const AIRDCPP_SEARCH_COMPLETE = "AIRDCPP_SEARCH_COMPLETE"; export const AIRDCPP_SEARCH_COMPLETE = "AIRDCPP_SEARCH_COMPLETE";
export const AIRDCPP_HUB_SEARCHES_SENT = "AIRDCPP_HUB_SEARCHES_SENT"; export const AIRDCPP_HUB_SEARCHES_SENT = "AIRDCPP_HUB_SEARCHES_SENT";

View File

@@ -1,6 +1,7 @@
import { import {
AIRDCPP_SEARCH_IN_PROGRESS, AIRDCPP_SEARCH_IN_PROGRESS,
AIRDCPP_SEARCH_RESULTS_RECEIVED, AIRDCPP_SEARCH_RESULTS_ADDED,
AIRDCPP_SEARCH_RESULTS_UPDATED,
AIRDCPP_HUB_SEARCHES_SENT, AIRDCPP_HUB_SEARCHES_SENT,
AIRDCPP_RESULT_DOWNLOAD_INITIATED, AIRDCPP_RESULT_DOWNLOAD_INITIATED,
AIRDCPP_DOWNLOAD_PROGRESS_TICK, AIRDCPP_DOWNLOAD_PROGRESS_TICK,
@@ -20,12 +21,23 @@ const initialState = {
function airdcppReducer(state = initialState, action) { function airdcppReducer(state = initialState, action) {
switch (action.type) { switch (action.type) {
case AIRDCPP_SEARCH_RESULTS_RECEIVED: case AIRDCPP_SEARCH_RESULTS_ADDED:
return { return {
...state, ...state,
searchResults: [...state.searchResults, action.groupedResult], searchResults: [...state.searchResults, action.groupedResult],
isAirDCPPSearchInProgress: true, 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: case AIRDCPP_SEARCH_IN_PROGRESS:
return { return {
...state, ...state,

View File

@@ -16,6 +16,6 @@ export const detectTradePaperbacks = (deck): any => {
return item; return item;
} }
}); });
console.log(compact(matches)); // console.log(compact(matches));
return compact(matches); return compact(matches);
}; };