cluedin-widget
Version: 
This project contains all the pages needed for browsing entities and searching them. The aim is to replace the CluedIn.Webapp project with this one when all the pages ( including the Admin page ) will be ported to REACT.
55 lines (48 loc) • 1.79 kB
JavaScript
import constants from '../constants';
const initialState = {
  genericLastDeals: {},
  isFetchingGenericDeals: true,
  isFakeGenericDeals: false,
  pageNumber: 0,
  currentTimeStamp: void 0,
  currentDeals: [],
};
export default function update(state = initialState, action = {}) {
  switch (action.type) {
    case constants.deal.REQUEST_GENERIC_LAST_DEALS:
      let timeStamp = action.data.timeStamp;
      let pageNumber = state.pageNumber;
      let currentDeals = state.currentDeals;
      let cleanGenericLastDeals = Object.assign({}, state.genericLastDeals);
      if (state.currentTimeStamp && state.currentTimeStamp !== action.data.timeStamp) {
        cleanGenericLastDeals[timeStamp] = void 0;
        pageNumber = 0;
        currentDeals = [];
      }
      return Object.assign({}, {
        genericLastDeals: cleanGenericLastDeals,
        isFetchingGenericDeals: true,
        isFakeGenericDeals: false,
        currentTimeStamp: timeStamp,
        pageNumber,
        currentDeals,
      });
    case constants.deal.RECEIVE_GENERIC_LAST_DEALS:
      let newGenericLastDeals = Object.assign({}, state.genericLastDeals);
      if (newGenericLastDeals[action.data.timeStamp]) {
        newGenericLastDeals[action.data.timeStamp] = newGenericLastDeals[action.data.timeStamp].concat(action.data.deals);
      } else {
        newGenericLastDeals[action.data.timeStamp] = action.data.deals;
      }
      return Object.assign({}, {
        genericLastDeals: newGenericLastDeals,
        isFetchingGenericDeals: false,
        isFakeGenericDeals: action.data.isFake,
        pageNumber: action.data.pageNumber,
        currentTimeStamp: state.currentTimeStamp,
        currentDeals: newGenericLastDeals[action.data.timeStamp],
      });
    default :
      return state;
  }
};