mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
105 lines (104 loc) • 3.11 kB
JavaScript
;
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.mainBindings = mainBindings;
exports.pluginEnabled = pluginEnabled;
const redux_1 = require("redux");
const action_types_1 = require("mattermost-redux/action_types");
const apps_1 = require("mattermost-redux/utils/apps");
function mainBindings(state = [], action) {
switch (action.type) {
case action_types_1.AppsTypes.FAILED_TO_FETCH_APP_BINDINGS: {
if (!state.length) {
return state;
}
return [];
}
case action_types_1.AppsTypes.RECEIVED_APP_BINDINGS: {
const bindings = action.data;
return (0, apps_1.validateBindings)(bindings);
}
case action_types_1.AppsTypes.APPS_PLUGIN_DISABLED: {
if (!state.length) {
return state;
}
return [];
}
default:
return state;
}
}
function mainForms(state = {}, action) {
switch (action.type) {
case action_types_1.AppsTypes.RECEIVED_APP_BINDINGS:
return {};
case action_types_1.AppsTypes.RECEIVED_APP_COMMAND_FORM: {
const { form, location } = action.data;
const newState = {
...state,
[location]: form,
};
return newState;
}
default:
return state;
}
}
const main = (0, redux_1.combineReducers)({
bindings: mainBindings,
forms: mainForms,
});
function rhsBindings(state = [], action) {
switch (action.type) {
case action_types_1.AppsTypes.RECEIVED_APP_RHS_BINDINGS: {
const bindings = action.data;
return (0, apps_1.validateBindings)(bindings);
}
default:
return state;
}
}
function rhsForms(state = {}, action) {
switch (action.type) {
case action_types_1.AppsTypes.RECEIVED_APP_RHS_BINDINGS:
return {};
case action_types_1.AppsTypes.RECEIVED_APP_RHS_COMMAND_FORM: {
const { form, location } = action.data;
const newState = {
...state,
[location]: form,
};
return newState;
}
default:
return state;
}
}
const rhs = (0, redux_1.combineReducers)({
bindings: rhsBindings,
forms: rhsForms,
});
function pluginEnabled(state = true, action) {
switch (action.type) {
case action_types_1.AppsTypes.APPS_PLUGIN_ENABLED: {
return true;
}
case action_types_1.AppsTypes.APPS_PLUGIN_DISABLED: {
return false;
}
case action_types_1.AppsTypes.RECEIVED_APP_BINDINGS: {
return true;
}
case action_types_1.AppsTypes.FAILED_TO_FETCH_APP_BINDINGS: {
return false;
}
default:
return state;
}
}
exports.default = (0, redux_1.combineReducers)({
main,
rhs,
pluginEnabled,
});