aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/ducks/utils/view.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/js/ducks/utils/view.js')
-rwxr-xr-xweb/src/js/ducks/utils/view.js28
1 files changed, 22 insertions, 6 deletions
diff --git a/web/src/js/ducks/utils/view.js b/web/src/js/ducks/utils/view.js
index 2f1e03fa..fdddc391 100755
--- a/web/src/js/ducks/utils/view.js
+++ b/web/src/js/ducks/utils/view.js
@@ -54,14 +54,30 @@ export default function reduce(state = defaultState, action) {
}
case UPDATE:
- if (state.indexOf[action.item.id] == null) {
- return
+ let hasOldItem = state.indexOf[action.item.id] !== null && state.indexOf[action.item.id] !== undefined
+ let hasNewItem = action.filter(action.item)
+ if (!hasNewItem && !hasOldItem) {
+ return state
}
- return {
- ...state,
- ...sortedUpdate(state, action.item, action.sort),
+ if (hasNewItem && !hasOldItem) {
+ return {
+ ...state,
+ ...sortedInsert(state, action.item, action.sort)
+ }
}
-
+ if (!hasNewItem && hasOldItem) {
+ return {
+ ...state,
+ ...sortedRemove(state, action.item.id)
+ }
+ }
+ if (hasNewItem && hasOldItem) {
+ return {
+ ...state,
+ ...sortedUpdate(state, action.item, action.sort),
+ }
+ }
+ break;
case RECEIVE:
{
const data = action.list.filter(action.filter).sort(action.sort)