2018-02-28 15:45:16 -05:00
|
|
|
import { Map } from 'immutable';
|
2021-01-13 19:51:45 +02:00
|
|
|
import { CONFIG_REQUEST, CONFIG_SUCCESS, CONFIG_FAILURE } from '../actions/config';
|
2019-12-18 18:16:02 +02:00
|
|
|
import { Config, ConfigAction } from '../types/redux';
|
2020-01-15 00:15:14 +02:00
|
|
|
import { EDITORIAL_WORKFLOW } from '../constants/publishModes';
|
2016-02-25 00:45:56 -08:00
|
|
|
|
2020-02-14 22:32:36 +02:00
|
|
|
const defaultState: Map<string, boolean | string> = Map({ isFetching: true });
|
|
|
|
|
2021-02-08 20:01:21 +02:00
|
|
|
function config(state = defaultState, action: ConfigAction) {
|
2016-02-25 00:45:56 -08:00
|
|
|
switch (action.type) {
|
2016-02-25 12:31:21 -08:00
|
|
|
case CONFIG_REQUEST:
|
2018-02-28 15:45:16 -05:00
|
|
|
return state.set('isFetching', true);
|
2016-02-25 12:31:21 -08:00
|
|
|
case CONFIG_SUCCESS:
|
2018-02-28 15:45:16 -05:00
|
|
|
/**
|
|
|
|
* The loadConfig action merges any existing config into the loaded config
|
|
|
|
* before firing this action (so the resulting config can be validated),
|
|
|
|
* so we don't have to merge it here.
|
|
|
|
*/
|
2021-01-13 19:51:45 +02:00
|
|
|
return action.payload;
|
2016-02-25 12:31:21 -08:00
|
|
|
case CONFIG_FAILURE:
|
2020-02-14 22:32:36 +02:00
|
|
|
return state.withMutations(s => {
|
|
|
|
s.delete('isFetching');
|
|
|
|
s.set('error', action.payload.toString());
|
|
|
|
});
|
2016-02-25 00:45:56 -08:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2021-02-08 20:01:21 +02:00
|
|
|
}
|
2016-06-10 00:16:01 -03:00
|
|
|
|
2021-02-08 20:01:21 +02:00
|
|
|
export function selectLocale(state: Config) {
|
|
|
|
return state.get('locale', 'en') as string;
|
|
|
|
}
|
2019-12-18 18:16:02 +02:00
|
|
|
|
2021-02-08 20:01:21 +02:00
|
|
|
export function selectUseWorkflow(state: Config) {
|
|
|
|
return state.get('publish_mode') === EDITORIAL_WORKFLOW;
|
|
|
|
}
|
2020-01-15 00:15:14 +02:00
|
|
|
|
2016-06-10 00:16:01 -03:00
|
|
|
export default config;
|