application/redux/reducers/assignment-view-reducers.js
import _ from 'lodash';
import {
ASSIGNMENT_VIEW_UPDATE,
ASSIGNMENT_VIEW_RESET,
ASSIGNMENT_VIEW_NOTIFY_NEW,
ASSIGNMENT_VIEW_CLEAR_NEW
} from './../actions/assignment-view-actions';
const baseState = {
filtersOn: false,
hasNew: false,
page: 1,
type: 'unscheduled',
keywords: null,
workflow: null,
status: null,
sorter: 'modified_at',
flip: false,
hpd: false,
cal: false,
calview: 'issue',
assignee: null,
currentView: 'unassigned',
issues: [],
start: null,
end: null,
useDate: null
};
export function assignmentView(state = null, action) {
if (state === null) {
state = baseState;
}
switch (action.type) {
case ASSIGNMENT_VIEW_UPDATE:
let newState = Object.assign({}, state, action.payload);
let testState = Object.assign({}, state, action.payload, {
filtersOn: false,
hasNew: false,
page: 1,
type: 'unscheduled',
currentView: 'unassigned',
calview: 'issue',
issues: [],
cal: false,
start: null,
end: null,
useDate: null
});
if (!_.isEqual(testState, baseState)) {
newState.filtersOn = true;
} else {
newState.filtersOn = false;
}
return newState;
case ASSIGNMENT_VIEW_RESET:
let updateState = {};
if (state.type) {
updateState['type'] = state.type;
}
if (localStorage.getItem("assignmentCurrentView")) {
updateState['currentView'] = localStorage.getItem("assignmentCurrentView");
}
return Object.assign({}, baseState, updateState);
case ASSIGNMENT_VIEW_NOTIFY_NEW:
return Object.assign({}, state, {hasNew: true});
case ASSIGNMENT_VIEW_CLEAR_NEW:
return Object.assign({}, state, {hasNew: false});
}
return state;
};