parent
b05b7ec4ad
commit
746da69070
|
@ -72,18 +72,31 @@ export default function createHandleActions(handlers, defaultState, section) {
|
|||
if (section === baseSection) {
|
||||
const newState = getSectionState(state, payloadSection);
|
||||
const items = newState.items;
|
||||
const index = _.findIndex(items, { id: payload.id });
|
||||
|
||||
if (!newState.itemMap) {
|
||||
newState.itemMap = createItemMap(items);
|
||||
}
|
||||
|
||||
const index = payload.id in newState.itemMap ? newState.itemMap[payload.id] : -1;
|
||||
|
||||
newState.items = [...items];
|
||||
|
||||
// TODO: Move adding to it's own reducer
|
||||
if (index >= 0) {
|
||||
const item = items[index];
|
||||
const newItem = { ...item, ...otherProps };
|
||||
|
||||
newState.items.splice(index, 1, { ...item, ...otherProps });
|
||||
// if the item to update is equal to existing, then don't actually update
|
||||
// to prevent costly reselections
|
||||
if (_.isEqual(item, newItem)) {
|
||||
return state;
|
||||
}
|
||||
|
||||
newState.items.splice(index, 1, newItem);
|
||||
} else if (!updateOnly) {
|
||||
newState.items.push({ ...otherProps });
|
||||
newState.itemMap = createItemMap(newState.items);
|
||||
const newIndex = newState.items.push({ ...otherProps }) - 1;
|
||||
|
||||
newState.itemMap[payload.id] = newIndex;
|
||||
}
|
||||
|
||||
return updateSectionState(state, payloadSection, newState);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { createSelector } from 'reselect';
|
||||
import createDeepEqualSelector from './createDeepEqualSelector';
|
||||
import { createSelector, createSelectorCreator, defaultMemoize } from 'reselect';
|
||||
import createClientSideCollectionSelector from './createClientSideCollectionSelector';
|
||||
import hasDifferentItemsOrOrder from 'Utilities/Object/hasDifferentItemsOrOrder';
|
||||
|
||||
function createUnoptimizedSelector(uiSection) {
|
||||
return createSelector(
|
||||
|
@ -26,8 +26,17 @@ function createUnoptimizedSelector(uiSection) {
|
|||
);
|
||||
}
|
||||
|
||||
function seriesListEqual(a, b) {
|
||||
return hasDifferentItemsOrOrder(a, b);
|
||||
}
|
||||
|
||||
const createSeriesEqualSelector = createSelectorCreator(
|
||||
defaultMemoize,
|
||||
seriesListEqual
|
||||
);
|
||||
|
||||
function createSeriesClientSideCollectionItemsSelector(uiSection) {
|
||||
return createDeepEqualSelector(
|
||||
return createSeriesEqualSelector(
|
||||
createUnoptimizedSelector(uiSection),
|
||||
(series) => series
|
||||
);
|
||||
|
|
|
@ -50,7 +50,6 @@ namespace Sonarr.Api.V3.Series
|
|||
public int TvRageId { get; set; }
|
||||
public int TvMazeId { get; set; }
|
||||
public DateTime? FirstAired { get; set; }
|
||||
public DateTime? LastInfoSync { get; set; }
|
||||
public SeriesTypes SeriesType { get; set; }
|
||||
public string CleanTitle { get; set; }
|
||||
public string ImdbId { get; set; }
|
||||
|
@ -109,7 +108,6 @@ namespace Sonarr.Api.V3.Series
|
|||
TvRageId = model.TvRageId,
|
||||
TvMazeId = model.TvMazeId,
|
||||
FirstAired = model.FirstAired,
|
||||
LastInfoSync = model.LastInfoSync,
|
||||
SeriesType = model.SeriesType,
|
||||
CleanTitle = model.CleanTitle,
|
||||
ImdbId = model.ImdbId,
|
||||
|
@ -167,7 +165,6 @@ namespace Sonarr.Api.V3.Series
|
|||
TvRageId = resource.TvRageId,
|
||||
TvMazeId = resource.TvMazeId,
|
||||
FirstAired = resource.FirstAired,
|
||||
LastInfoSync = resource.LastInfoSync,
|
||||
SeriesType = resource.SeriesType,
|
||||
CleanTitle = resource.CleanTitle,
|
||||
ImdbId = resource.ImdbId,
|
||||
|
|
Loading…
Reference in New Issue