Merge branch 'federation-modal' into 'main'
Fix federation modal See merge request soapbox-pub/soapbox!2850
This commit is contained in:
commit
ded13132ff
3 changed files with 14 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
|||
import { Map as ImmutableMap, Set as ImmutableSet } from 'immutable';
|
||||
import { Set as ImmutableSet } from 'immutable';
|
||||
|
||||
import ConfigDB from 'soapbox/utils/config-db';
|
||||
|
||||
|
@ -7,9 +7,9 @@ import { fetchConfig, updateConfig } from './admin';
|
|||
import type { MRFSimple } from 'soapbox/schemas/pleroma';
|
||||
import type { AppDispatch, RootState } from 'soapbox/store';
|
||||
|
||||
const simplePolicyMerge = (simplePolicy: MRFSimple, host: string, restrictions: ImmutableMap<string, any>) => {
|
||||
const simplePolicyMerge = (simplePolicy: MRFSimple, host: string, restrictions: Record<string, any>) => {
|
||||
const entries = Object.entries(simplePolicy).map(([key, hosts]) => {
|
||||
const isRestricted = restrictions.get(key);
|
||||
const isRestricted = restrictions[key];
|
||||
|
||||
if (isRestricted) {
|
||||
return [key, ImmutableSet(hosts).add(host).toJS()];
|
||||
|
@ -21,7 +21,7 @@ const simplePolicyMerge = (simplePolicy: MRFSimple, host: string, restrictions:
|
|||
return Object.fromEntries(entries);
|
||||
};
|
||||
|
||||
const updateMrf = (host: string, restrictions: ImmutableMap<string, any>) =>
|
||||
const updateMrf = (host: string, restrictions: Record<string, any>) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) =>
|
||||
dispatch(fetchConfig())
|
||||
.then(() => {
|
||||
|
|
|
@ -30,24 +30,25 @@ const EditFederationModal: React.FC<IEditFederationModal> = ({ host, onClose })
|
|||
const getRemoteInstance = useCallback(makeGetRemoteInstance(), []);
|
||||
const remoteInstance = useAppSelector(state => getRemoteInstance(state, host));
|
||||
|
||||
const [data, setData] = useState({} as any);
|
||||
const [data, setData] = useState<Record<string, any>>({});
|
||||
|
||||
useEffect(() => {
|
||||
setData(remoteInstance.get('federation'));
|
||||
setData(remoteInstance.get('federation') as Record<string, any>);
|
||||
}, [remoteInstance]);
|
||||
|
||||
const handleDataChange = (key: string): React.ChangeEventHandler<HTMLInputElement> => {
|
||||
return ({ target }) => {
|
||||
setData(data.set(key, target.checked));
|
||||
setData({ ...data, [key]: target.checked });
|
||||
};
|
||||
};
|
||||
|
||||
const handleMediaRemoval: React.ChangeEventHandler<HTMLInputElement> = ({ target: { checked } }) => {
|
||||
const newData = data.merge({
|
||||
const newData = {
|
||||
...data,
|
||||
avatar_removal: checked,
|
||||
banner_removal: checked,
|
||||
media_removal: checked,
|
||||
});
|
||||
};
|
||||
|
||||
setData(newData);
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@ import trimStart from 'lodash/trimStart';
|
|||
import { type MRFSimple, mrfSimpleSchema } from 'soapbox/schemas/pleroma';
|
||||
|
||||
export type Config = ImmutableMap<string, any>;
|
||||
export type Policy = ImmutableMap<string, any>;
|
||||
export type Policy = Record<string, any>;
|
||||
|
||||
const find = (
|
||||
configs: ImmutableList<Config>,
|
||||
|
@ -40,15 +40,15 @@ const toSimplePolicy = (configs: ImmutableList<Config>): MRFSimple => {
|
|||
};
|
||||
|
||||
const fromSimplePolicy = (simplePolicy: Policy): ImmutableList<Config> => {
|
||||
const mapper = (hosts: ImmutableList<string>, key: string) => fromJS({ tuple: [`:${key}`, hosts.toJS()] });
|
||||
const mapper = ([key, hosts]: [key: string, hosts: ImmutableList<string>]) => fromJS({ tuple: [`:${key}`, hosts] });
|
||||
|
||||
const value = simplePolicy.map(mapper).toList();
|
||||
const value = Object.entries(simplePolicy).map(mapper);
|
||||
|
||||
return ImmutableList([
|
||||
ImmutableMap({
|
||||
group: ':pleroma',
|
||||
key: ':mrf_simple',
|
||||
value,
|
||||
value: ImmutableList(value),
|
||||
}),
|
||||
]);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue