UNPKG

mattermost-redux

Version:

Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client

56 lines (55 loc) 2.04 kB
"use strict"; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.byChannelId = byChannelId; const redux_1 = require("redux"); const action_types_1 = require("mattermost-redux/action_types"); const toNewObj = (current, arr) => { return arr.reduce((acc, x) => { return { ...acc, [x.id]: x }; }, { ...current }); }; function byChannelId(state = {}, action) { switch (action.type) { case action_types_1.ChannelBookmarkTypes.RECEIVED_BOOKMARKS: { const channelId = action.data.channelId; const bookmarks = action.data.bookmarks; return { ...state, [channelId]: toNewObj(state[channelId], bookmarks), }; } case action_types_1.ChannelBookmarkTypes.RECEIVED_BOOKMARK: { const bookmark = action.data; const { id, channel_id: channelId } = bookmark; return { ...state, [channelId]: { ...state[channelId], [id]: bookmark, }, }; } case action_types_1.ChannelBookmarkTypes.BOOKMARK_DELETED: { const bookmark = action.data; const channelNextState = { ...state[bookmark.channel_id] }; Reflect.deleteProperty(channelNextState, bookmark.id); const nextState = { ...state, [bookmark.channel_id]: channelNextState }; return nextState; } case action_types_1.ChannelTypes.LEAVE_CHANNEL: { const channelId = action.data.channelId; const nextState = { ...state }; Reflect.deleteProperty(nextState, channelId); return nextState; } case action_types_1.UserTypes.LOGOUT_SUCCESS: return {}; default: return state; } } exports.default = (0, redux_1.combineReducers)({ byChannelId, });