UNPKG

mattermost-redux

Version:

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

115 lines (114 loc) 3.53 kB
"use strict"; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. Object.defineProperty(exports, "__esModule", { value: true }); const redux_1 = require("redux"); const action_types_1 = require("mattermost-redux/action_types"); function settings(state = {}, action) { switch (action.type) { case action_types_1.ContentFlaggingTypes.RECEIVED_CONTENT_FLAGGING_CONFIG: { return { ...state, ...action.data, }; } case action_types_1.UserTypes.LOGOUT_SUCCESS: return {}; default: return state; } } function fields(state = {}, action) { switch (action.type) { case action_types_1.ContentFlaggingTypes.RECEIVED_POST_CONTENT_FLAGGING_FIELDS: { return { ...state, ...action.data, }; } case action_types_1.UserTypes.LOGOUT_SUCCESS: return {}; default: return state; } } function postValues(state = {}, action) { switch (action.type) { case action_types_1.ContentFlaggingTypes.RECEIVED_POST_CONTENT_FLAGGING_VALUES: { return { ...state, [action.data.postId]: action.data.values, }; } case action_types_1.ContentFlaggingTypes.CONTENT_FLAGGING_REPORT_VALUE_UPDATED: { const postId = action.data.target_id; const existingPropertyValues = state[postId] || {}; const updatedPropertyValues = JSON.parse(action.data.property_values); const valuesByFieldId = {}; existingPropertyValues.forEach((property) => { valuesByFieldId[property.field_id] = property; }); updatedPropertyValues.forEach((property) => { valuesByFieldId[property.field_id] = property; }); return { ...state, [postId]: Object.values(valuesByFieldId), }; } case action_types_1.UserTypes.LOGOUT_SUCCESS: return {}; default: return state; } } function flaggedPosts(state = {}, action) { switch (action.type) { case action_types_1.ContentFlaggingTypes.RECEIVED_FLAGGED_POST: { return { ...state, [action.data.id]: action.data, }; } case action_types_1.UserTypes.LOGOUT_SUCCESS: return {}; default: return state; } } function channels(state = {}, action) { switch (action.type) { case action_types_1.ContentFlaggingTypes.RECEIVED_CONTENT_FLAGGING_CHANNEL: { return { ...state, [action.data.id]: action.data, }; } case action_types_1.UserTypes.LOGOUT_SUCCESS: return {}; default: return state; } } function teams(state = {}, action) { switch (action.type) { case action_types_1.ContentFlaggingTypes.RECEIVED_CONTENT_FLAGGING_TEAM: { return { ...state, [action.data.id]: action.data, }; } case action_types_1.UserTypes.LOGOUT_SUCCESS: return {}; default: return state; } } exports.default = (0, redux_1.combineReducers)({ settings, fields, postValues, flaggedPosts, channels, teams, });