bigbuffet-rw/app/soapbox/reducers/soapbox.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-08-23 10:48:45 -07:00
import { ADMIN_CONFIG_UPDATE_SUCCESS } from '../actions/admin';
import {
SOAPBOX_CONFIG_REQUEST_SUCCESS,
SOAPBOX_CONFIG_REQUEST_FAIL,
} from '../actions/soapbox';
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
// TODO: Handle this more like getSettings()
2020-08-23 10:48:45 -07:00
const initialState = ImmutableMap({
logo: '',
banner: '',
brandColor: '#0482d8', // Azure
customCss: ImmutableList([]),
promoPanel: ImmutableMap({
items: ImmutableList([]),
}),
2020-08-23 10:48:45 -07:00
extensions: ImmutableMap(),
defaultSettings: ImmutableMap(),
copyright: '♥2020. Copying is an act of love. Please copy and share.',
navlinks: ImmutableMap({
2020-08-23 10:48:45 -07:00
homeFooter: ImmutableList(),
}),
});
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;
};
export default function soapbox(state = initialState, action) {
switch(action.type) {
case SOAPBOX_CONFIG_REQUEST_SUCCESS:
2020-08-23 10:48:45 -07:00
return initialState.mergeDeep(ImmutableMap(fromJS(action.soapboxConfig)));
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));
default:
return state;
}
};