ConfigDB: Refactor updateFromAdmin in reducers/soapbox

preload
Alex Gleason 4 years ago
parent e1a86d4e1c
commit 48d0572403
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

File diff suppressed because it is too large Load Diff

@ -1,12 +1,21 @@
import { ADMIN_CONFIG_UPDATE_SUCCESS } from '../actions/admin';
import { SOAPBOX_CONFIG_REQUEST_SUCCESS } from '../actions/soapbox';
import { Map as ImmutableMap, fromJS } from 'immutable';
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
import { ConfigDB } from 'soapbox/utils/config_db';
const initialState = ImmutableMap();
const updateFromAdmin = (state, config) => {
// TODO: Generalize this with an API similar to `Pleroma.Config` in Pleroma BE
return config.getIn(['configs', 0, 'value', 0, 'tuple', 1], state);
const configs = config.get('configs', ImmutableList());
try {
return ConfigDB.find(configs, ':pleroma', ':frontend_configurations')
.get('value')
.find(value => value.getIn(['tuple', 0] === ':soapbox_fe'))
.getIn(['tuple', 1]);
} catch {
return state;
}
};
export default function soapbox(state = initialState, action) {

@ -0,0 +1,12 @@
import { ConfigDB } from '../config_db';
import config_db from 'soapbox/__fixtures__/config_db.json';
import { fromJS } from 'immutable';
test('find', () => {
const configs = fromJS(config_db).get('configs');
expect(ConfigDB.find(configs, ':phoenix', ':json_library')).toEqual(fromJS({
group: ':phoenix',
key: ':json_library',
value: 'Jason',
}));
});

@ -0,0 +1,9 @@
export const ConfigDB = {
find: (configs, group, key) => {
return configs.find(config =>
config.isSuperset({ group, key })
);
},
};
export default ConfigDB;
Loading…
Cancel
Save