import Immutable from 'seamless-immutable';
import {
  REQUEST_FEED_NOTIFICATIONS,
  REQUEST_FEED_NOTIFICATIONS_SUCCESS,
  REQUEST_FEED_NOTIFICATIONS_FAILURE,
  CHANGE_TYPE_FILTER,
} from 'actions/feedActions';

const initialState = Immutable({
  listOfFeedNotifications: [],
  sentRequestForList: false,
  receivedList: false,
  errorMessage: '',
  currentOffset: 0,
  typeFilter: 'ALL',
});

function feedReducer(state = initialState, action) {
  switch (action.type) {
    case REQUEST_FEED_NOTIFICATIONS:
      return Immutable.merge(state, {
        sentRequestForList: true,
        receivedList: false,
      });
    case REQUEST_FEED_NOTIFICATIONS_SUCCESS:
      return Immutable.merge(state, {
        sentRequestForList: false,
        receivedList: true,
        errorMessage: '',
        listOfFeedNotifications: state.listOfFeedNotifications.concat(
          action.payload.listOfNotifications,
        ),
        currentOffset:
          state.currentOffset + action.payload.listOfNotifications.length,
      });
    case REQUEST_FEED_NOTIFICATIONS_FAILURE:
      return Immutable.merge(state, {
        sentRequestForList: false,
        receivedList: false,
        errorMessage: action.payload,
      });
    case CHANGE_TYPE_FILTER:
      return Immutable.merge(state, {
        typeFilter: action.payload,
      });
    default:
      return state;
  }
}

export default feedReducer;

@@ -1,12 +1,54 @@
+/* eslint-disable no-case-declarations */%0A
 import Immut
@@ -79,16 +79,41 @@
 table';%0A
+import _ from 'lodash';%0A%0A
 import %7B
@@ -725,16 +725,191 @@
 UCCESS:%0A
+      const newListOfNotifications = _.unionWith(%0A        state.listOfFeedNotifications,%0A        action.payload.listOfNotifications,%0A        (a, b) =%3E a.id === b.id,%0A      );%0A
       re
@@ -1064,72 +1064,12 @@
 ns: 
-state.listOfFeedNotifications.concat(%0A          action.payload.l
+newL
 istO
@@ -1088,19 +1088,8 @@
 ns,%0A
-        ),%0A
     
@@ -1110,57 +1110,13 @@
 set:
-%0A          state.currentOffset + action.payload.l
+ newL
 istO

use lodash union to merge the newly fetched notifications (avoids duplicates)