mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
64 lines (63 loc) • 2.07 kB
JavaScript
;
// 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,
};
}
default:
return state;
}
}
function fields(state = {}, action) {
switch (action.type) {
case action_types_1.ContentFlaggingTypes.RECEIVED_POST_CONTENT_FLAGGING_FIELDS: {
return {
...state,
...action.data,
};
}
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),
};
}
default:
return state;
}
}
exports.default = (0, redux_1.combineReducers)({
settings,
fields,
postValues,
});