2020-08-23 10:48:45 -07:00
|
|
|
import { ADMIN_CONFIG_UPDATE_SUCCESS } from '../actions/admin';
|
2020-08-31 20:00:11 -07:00
|
|
|
import {
|
|
|
|
SOAPBOX_CONFIG_REQUEST_SUCCESS,
|
|
|
|
SOAPBOX_CONFIG_REQUEST_FAIL,
|
|
|
|
} from '../actions/soapbox';
|
2020-10-15 14:59:42 -07:00
|
|
|
import { PRELOAD_IMPORT } from 'soapbox/actions/preload';
|
2020-12-29 21:25:07 -08:00
|
|
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
2020-08-24 08:08:39 -07:00
|
|
|
import { ConfigDB } from 'soapbox/utils/config_db';
|
2020-04-01 12:38:08 -07:00
|
|
|
|
2020-08-23 13:56:18 -07:00
|
|
|
const initialState = ImmutableMap();
|
2020-06-03 12:47:49 -07:00
|
|
|
|
2020-09-02 19:47:46 -07:00
|
|
|
const fallbackState = ImmutableMap({
|
|
|
|
brandColor: '#0482d8', // Azure
|
|
|
|
});
|
|
|
|
|
2020-12-29 21:25:07 -08:00
|
|
|
const updateFromAdmin = (state, configs) => {
|
2020-08-24 08:08:39 -07:00
|
|
|
try {
|
|
|
|
return ConfigDB.find(configs, ':pleroma', ':frontend_configurations')
|
|
|
|
.get('value')
|
2020-08-24 08:38:29 -07:00
|
|
|
.find(value => value.getIn(['tuple', 0]) === ':soapbox_fe')
|
2020-08-24 08:08:39 -07:00
|
|
|
.getIn(['tuple', 1]);
|
|
|
|
} catch {
|
|
|
|
return state;
|
|
|
|
}
|
2020-08-23 10:48:45 -07:00
|
|
|
};
|
|
|
|
|
2020-10-15 14:59:42 -07:00
|
|
|
const preloadImport = (state, action) => {
|
|
|
|
const path = '/api/pleroma/frontend_configurations';
|
|
|
|
const feData = action.data[path];
|
|
|
|
|
|
|
|
if (feData) {
|
|
|
|
const soapbox = feData.soapbox_fe;
|
|
|
|
return soapbox ? fallbackState.mergeDeep(fromJS(soapbox)) : fallbackState;
|
|
|
|
} else {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-01 12:38:08 -07:00
|
|
|
export default function soapbox(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
2020-10-15 14:59:42 -07:00
|
|
|
case PRELOAD_IMPORT:
|
|
|
|
return preloadImport(state, action);
|
2020-06-03 12:24:53 -07:00
|
|
|
case SOAPBOX_CONFIG_REQUEST_SUCCESS:
|
2020-08-23 13:56:18 -07:00
|
|
|
return fromJS(action.soapboxConfig);
|
2020-08-31 20:00:11 -07:00
|
|
|
case SOAPBOX_CONFIG_REQUEST_FAIL:
|
2020-09-03 09:10:03 -07:00
|
|
|
return fallbackState.mergeDeep(state);
|
2020-08-23 10:48:45 -07:00
|
|
|
case ADMIN_CONFIG_UPDATE_SUCCESS:
|
2020-12-29 21:25:07 -08:00
|
|
|
return updateFromAdmin(state, fromJS(action.configs));
|
2020-04-01 12:38:08 -07:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|