mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
53 lines (52 loc) • 1.89 kB
JavaScript
;
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = recapsReducer;
const action_types_1 = require("mattermost-redux/action_types");
const initialState = {
byId: {},
allIds: [],
};
function recapsReducer(state = initialState, action) {
switch (action.type) {
case action_types_1.RecapTypes.RECEIVED_RECAP: {
const recap = action.data;
const nextState = { ...state };
nextState.byId = {
...state.byId,
[recap.id]: recap,
};
if (!state.allIds.includes(recap.id)) {
nextState.allIds = [...state.allIds, recap.id];
}
return nextState;
}
case action_types_1.RecapTypes.RECEIVED_RECAPS: {
const recaps = action.data;
const nextState = { ...state };
const newById = { ...state.byId };
const newAllIds = new Set(state.allIds);
recaps.forEach((recap) => {
newById[recap.id] = recap;
newAllIds.add(recap.id);
});
nextState.byId = newById;
nextState.allIds = Array.from(newAllIds);
return nextState;
}
case action_types_1.RecapTypes.DELETE_RECAP_SUCCESS: {
const { recapId } = action.data;
const nextState = { ...state };
const newById = { ...state.byId };
delete newById[recapId];
nextState.byId = newById;
nextState.allIds = state.allIds.filter((id) => id !== recapId);
return nextState;
}
case action_types_1.UserTypes.LOGOUT_SUCCESS:
return initialState;
default:
return state;
}
}