2016-02-25 00:45:56 -08:00
|
|
|
import Immutable from 'immutable';
|
2016-10-10 15:34:21 -03:00
|
|
|
import _ from 'lodash';
|
|
|
|
import * as publishModes from '../constants/publishModes';
|
2016-02-25 12:31:21 -08:00
|
|
|
import { CONFIG_REQUEST, CONFIG_SUCCESS, CONFIG_FAILURE } from '../actions/config';
|
2016-02-25 00:45:56 -08:00
|
|
|
|
2016-10-10 15:34:21 -03:00
|
|
|
const defaults = {
|
|
|
|
publish_mode: publishModes.SIMPLE
|
|
|
|
};
|
|
|
|
|
|
|
|
const applyDefaults = (config) => {
|
|
|
|
// Make sure there is a public folder
|
|
|
|
_.set(defaults,
|
|
|
|
'public_folder',
|
|
|
|
config.media_folder.charAt(0) === '/' ? config.media_folder : '/' + config.media_folder);
|
|
|
|
|
|
|
|
return _.defaultsDeep(config, defaults);
|
|
|
|
};
|
|
|
|
|
2016-06-10 00:16:01 -03:00
|
|
|
const config = (state = null, action) => {
|
2016-02-25 00:45:56 -08:00
|
|
|
switch (action.type) {
|
2016-02-25 12:31:21 -08:00
|
|
|
case CONFIG_REQUEST:
|
2016-06-16 22:49:48 -03:00
|
|
|
return Immutable.Map({ isFetching: true });
|
2016-02-25 12:31:21 -08:00
|
|
|
case CONFIG_SUCCESS:
|
2016-10-10 15:34:21 -03:00
|
|
|
const config = applyDefaults(action.payload);
|
|
|
|
return Immutable.fromJS(config);
|
2016-02-25 12:31:21 -08:00
|
|
|
case CONFIG_FAILURE:
|
2016-06-16 22:49:48 -03:00
|
|
|
return Immutable.Map({ error: action.payload.toString() });
|
2016-02-25 00:45:56 -08:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2016-06-10 00:16:01 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default config;
|