2020-08-23 10:48:45 -07:00
|
|
|
import { ADMIN_CONFIG_UPDATE_SUCCESS } from '../actions/admin';
|
2020-06-03 12:47:49 -07:00
|
|
|
import {
|
|
|
|
SOAPBOX_CONFIG_REQUEST_SUCCESS,
|
|
|
|
SOAPBOX_CONFIG_REQUEST_FAIL,
|
|
|
|
} from '../actions/soapbox';
|
2020-08-12 15:24:14 -07:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
2020-04-01 12:38:08 -07:00
|
|
|
|
2020-08-23 13:04:32 -07:00
|
|
|
// TODO: Handle this more like getSettings()
|
2020-08-23 10:48:45 -07:00
|
|
|
const initialState = ImmutableMap({
|
2020-08-12 15:24:14 -07:00
|
|
|
logo: '',
|
|
|
|
banner: '',
|
2020-06-03 12:47:49 -07:00
|
|
|
brandColor: '#0482d8', // Azure
|
2020-08-14 14:51:04 -07:00
|
|
|
customCss: ImmutableList([]),
|
2020-08-12 15:24:14 -07:00
|
|
|
promoPanel: ImmutableMap({
|
|
|
|
items: ImmutableList([]),
|
|
|
|
}),
|
2020-08-23 10:48:45 -07:00
|
|
|
extensions: ImmutableMap(),
|
|
|
|
defaultSettings: ImmutableMap(),
|
2020-08-14 17:03:11 -07:00
|
|
|
copyright: '♥2020. Copying is an act of love. Please copy and share.',
|
2020-08-12 15:24:14 -07:00
|
|
|
navlinks: ImmutableMap({
|
2020-08-23 10:48:45 -07:00
|
|
|
homeFooter: ImmutableList(),
|
2020-08-12 15:24:14 -07:00
|
|
|
}),
|
2020-06-03 12:47:49 -07:00
|
|
|
});
|
|
|
|
|
2020-08-23 10:48:45 -07:00
|
|
|
const updateFromAdmin = (state, config) => {
|
|
|
|
// TODO: Generalize this with an API similar to `Pleroma.Config` in Pleroma BE
|
|
|
|
const soapboxConfig = config.getIn(['configs', 0, 'value', 0, 'tuple', 1]);
|
|
|
|
if (soapboxConfig) return state.mergeDeep(soapboxConfig);
|
|
|
|
return state;
|
|
|
|
};
|
|
|
|
|
2020-04-01 12:38:08 -07:00
|
|
|
export default function soapbox(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
2020-06-03 12:24:53 -07:00
|
|
|
case SOAPBOX_CONFIG_REQUEST_SUCCESS:
|
2020-08-23 10:48:45 -07:00
|
|
|
return initialState.mergeDeep(ImmutableMap(fromJS(action.soapboxConfig)));
|
2020-06-03 12:47:49 -07:00
|
|
|
case SOAPBOX_CONFIG_REQUEST_FAIL:
|
2020-08-23 10:48:45 -07:00
|
|
|
return initialState;
|
|
|
|
case ADMIN_CONFIG_UPDATE_SUCCESS:
|
|
|
|
return updateFromAdmin(state, fromJS(action.config));
|
2020-04-01 12:38:08 -07:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|