From 97ec1847541ba2a73d25eedbd3c97aa6f2f7e4e0 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 20 Apr 2020 09:35:35 -0700 Subject: [PATCH] Fixed: Import series failing to add items to process --- frontend/src/Store/Actions/Creators/createHandleActions.js | 5 +++-- frontend/src/Store/Actions/importSeriesActions.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/Store/Actions/Creators/createHandleActions.js b/frontend/src/Store/Actions/Creators/createHandleActions.js index dc7b9cbd6..36a103da1 100644 --- a/frontend/src/Store/Actions/Creators/createHandleActions.js +++ b/frontend/src/Store/Actions/Creators/createHandleActions.js @@ -72,8 +72,9 @@ export default function createHandleActions(handlers, defaultState, section) { if (section === baseSection) { const newState = getSectionState(state, payloadSection); const items = newState.items; + const itemMap = newState.itemMap ?? {}; - const index = payload.id in newState.itemMap ? newState.itemMap[payload.id] : -1; + const index = payload.id in itemMap ? itemMap[payload.id] : -1; newState.items = [...items]; @@ -92,7 +93,7 @@ export default function createHandleActions(handlers, defaultState, section) { } else if (!updateOnly) { const newIndex = newState.items.push({ ...otherProps }) - 1; - newState.itemMap = { ...newState.itemMap }; + newState.itemMap = { ...itemMap }; newState.itemMap[payload.id] = newIndex; } diff --git a/frontend/src/Store/Actions/importSeriesActions.js b/frontend/src/Store/Actions/importSeriesActions.js index 04db50092..347d7b572 100644 --- a/frontend/src/Store/Actions/importSeriesActions.js +++ b/frontend/src/Store/Actions/importSeriesActions.js @@ -221,12 +221,12 @@ export const actionHandlers = handleThunks({ const addedIds = []; const allNewSeries = ids.reduce((acc, id) => { - const item = _.find(items, { id }); + const item = items.find((i) => i.id === id); const selectedSeries = item.selectedSeries; // Make sure we have a selected series and // the same series hasn't been added yet. - if (selectedSeries && !_.some(acc, { tvdbId: selectedSeries.tvdbId })) { + if (selectedSeries && !acc.some((a) => a.tvdbId === selectedSeries.tvdbId)) { const newSeries = getNewSeries(_.cloneDeep(selectedSeries), item); newSeries.path = item.path; @@ -318,7 +318,7 @@ export const reducers = createHandleActions({ [SET_IMPORT_SERIES_VALUE]: function(state, { payload }) { const newState = getSectionState(state, section); const items = newState.items; - const index = _.findIndex(items, { id: payload.id }); + const index = items.findIndex((item) => item.id === payload.id); newState.items = [...items];