diff --git a/src/features/federation-restrictions/components/instance-restrictions.tsx b/src/features/federation-restrictions/components/instance-restrictions.tsx index bb0b2c2ec7..344dc766d2 100644 --- a/src/features/federation-restrictions/components/instance-restrictions.tsx +++ b/src/features/federation-restrictions/components/instance-restrictions.tsx @@ -5,10 +5,10 @@ import Icon from 'soapbox/components/icon'; import { HStack, Stack, Text } from 'soapbox/components/ui'; import { useInstance } from 'soapbox/hooks'; -import type { Map as ImmutableMap } from 'immutable'; +import type { RemoteInstance } from 'soapbox/selectors'; -const hasRestrictions = (remoteInstance: ImmutableMap): boolean => { - const { accept, reject_deletes, report_removal, ...federation } = remoteInstance.get('federation'); +const hasRestrictions = (remoteInstance: RemoteInstance): boolean => { + const { accept, reject_deletes, report_removal, ...federation } = remoteInstance.federation; return !!Object.values(federation).reduce((acc, value) => Boolean(acc || value), false); }; @@ -30,7 +30,7 @@ const Restriction: React.FC = ({ icon, children }) => { }; interface IInstanceRestrictions { - remoteInstance: ImmutableMap; + remoteInstance: RemoteInstance; } const InstanceRestrictions: React.FC = ({ remoteInstance }) => { @@ -46,7 +46,7 @@ const InstanceRestrictions: React.FC = ({ remoteInstance followers_only, media_nsfw, media_removal, - } = remoteInstance.get('federation').toJS(); + } = remoteInstance.federation; const fullMediaRemoval = media_removal && avatar_removal && banner_removal; const partialMediaRemoval = media_removal || avatar_removal || banner_removal; @@ -108,10 +108,10 @@ const InstanceRestrictions: React.FC = ({ remoteInstance const renderContent = () => { if (!instance || !remoteInstance) return null; - const host = remoteInstance.get('host'); + const host = remoteInstance.host; const siteTitle = instance.title; - if (remoteInstance.getIn(['federation', 'reject']) === true) { + if (remoteInstance.federation.reject === true) { return ( = ({ host }) => {
-
- {remoteInstance.get('host')} +
+ {remoteInstance.host}
= ({ host }) => { return ( = ({ host, onClose }) const [data, setData] = useState>({}); useEffect(() => { - setData(remoteInstance.get('federation') as Record); + setData(remoteInstance.federation); }, [remoteInstance]); const handleDataChange = (key: string): React.ChangeEventHandler => { diff --git a/src/selectors/index.ts b/src/selectors/index.ts index 6d0809db8e..6bd738e0e8 100644 --- a/src/selectors/index.ts +++ b/src/selectors/index.ts @@ -2,6 +2,7 @@ import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, + Record as ImmutableRecord, fromJS, } from 'immutable'; import { createSelector } from 'reselect'; @@ -305,7 +306,7 @@ const getRemoteInstanceFavicon = (state: RootState, host: string) => { return account?.pleroma?.favicon; }; -type HostFederation = { +export type HostFederation = { [key in keyof MRFSimple]: boolean; }; @@ -328,19 +329,25 @@ export const makeGetHosts = () => { }); }; -export const makeGetRemoteInstance = () => { - return createSelector([ +export const RemoteInstanceRecord = ImmutableRecord({ + host: '', + favicon: null as string | null, + federation: null as unknown as HostFederation, +}); + +export type RemoteInstance = ReturnType; + +export const makeGetRemoteInstance = () => + createSelector([ (_state: RootState, host: string) => host, getRemoteInstanceFavicon, getRemoteInstanceFederation, - ], (host, favicon, federation) => { - return ImmutableMap({ + ], (host, favicon, federation) => + RemoteInstanceRecord({ host, favicon, federation, - }); - }); -}; + })); type ColumnQuery = { type: string; prefix?: string };