UNPKG

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.93 kB
import constants from '../constants'; const initialState = { genericLastDocuments: {}, isFetchingGenericDocuments: true, isFakeGenericDocuments: false, pageNumber: 0, currentTimeStamp: void 0, currentDocuments: [], }; export default function update(state = initialState, action = {}) { switch (action.type) { case constants.document.REQUEST_GENERIC_LAST_DOCUMENTS: let timeStamp = action.data.timeStamp; let pageNumber = state.pageNumber; let currentDocuments = state.currentDocuments; let cleanGenericLastDocuments = Object.assign({}, state.genericLastDocuments); if (state.currentTimeStamp && state.currentTimeStamp !== action.data.timeStamp) { cleanGenericLastDocuments[timeStamp] = void 0; pageNumber = 0; currentDocuments = []; } return Object.assign({}, { genericLastDocuments: cleanGenericLastDocuments, isFetchingGenericDocuments: true, isFakeGenericDocuments: false, pageNumber, currentTimeStamp: timeStamp, currentDocuments, }); case constants.document.RECEIVE_GENERIC_LAST_DOCUMENTS: let newGenericLastDocuments = Object.assign({}, state.genericLastDocuments); if (newGenericLastDocuments[action.data.timeStamp]) { newGenericLastDocuments[action.data.timeStamp] = newGenericLastDocuments[action.data.timeStamp].concat(action.data.documents); } else { newGenericLastDocuments[action.data.timeStamp] = action.data.documents; } return Object.assign({}, { genericLastDocuments: newGenericLastDocuments, isFetchingGenericDocuments: false, isFakeGenericDocuments: action.data.isFake, pageNumber: action.data.pageNumber, currentTimeStamp: state.currentTimeStamp, currentDocuments: newGenericLastDocuments[action.data.timeStamp], }); default : return state; } };