diff --git a/app/soapbox/features/ui/components/instance_info_panel.js b/app/soapbox/features/ui/components/instance_info_panel.js deleted file mode 100644 index 20582ddcfd..0000000000 Binary files a/app/soapbox/features/ui/components/instance_info_panel.js and /dev/null differ diff --git a/app/soapbox/features/ui/components/instance_info_panel.tsx b/app/soapbox/features/ui/components/instance_info_panel.tsx new file mode 100644 index 0000000000..a100abc2c6 --- /dev/null +++ b/app/soapbox/features/ui/components/instance_info_panel.tsx @@ -0,0 +1,68 @@ +'use strict'; + +import React from 'react'; +import { useIntl, defineMessages } from 'react-intl'; + +import { pinHost, unpinHost } from 'soapbox/actions/remote_timeline'; +import DropdownMenu from 'soapbox/containers/dropdown_menu_container'; +import { useAppSelector, useAppDispatch, useSettings } from 'soapbox/hooks'; +import { makeGetRemoteInstance } from 'soapbox/selectors'; + +const getRemoteInstance = makeGetRemoteInstance(); + +const messages = defineMessages({ + pinHost: { id: 'remote_instance.pin_host', defaultMessage: 'Pin {host}' }, + unpinHost: { id: 'remote_instance.unpin_host', defaultMessage: 'Unpin {host}' }, +}); + +interface IInstanceInfoPanel { + /** Hostname (domain) of the remote instance, eg "gleasonator.com" */ + host: string, +} + +/** Widget that displays information about a remote instance to users. */ +const InstanceInfoPanel: React.FC = ({ host }) => { + const intl = useIntl(); + const dispatch = useAppDispatch(); + + const settings = useSettings(); + const remoteInstance: any = useAppSelector(state => getRemoteInstance(state, host)); + const pinned: boolean = (settings.getIn(['remote_timeline', 'pinnedHosts']) as any).includes(host); + + const handlePinHost: React.MouseEventHandler = () => { + if (!pinned) { + dispatch(pinHost(host)); + } else { + dispatch(unpinHost(host)); + } + }; + + const makeMenu = () => { + return [{ + text: intl.formatMessage(pinned ? messages.unpinHost : messages.pinHost, { host }), + action: handlePinHost, + icon: require(pinned ? '@tabler/icons/icons/pinned-off.svg' : '@tabler/icons/icons/pin.svg'), + }]; + }; + + const menu = makeMenu(); + const icon = pinned ? 'thumbtack' : 'globe-w'; + + if (!remoteInstance) return null; + + return ( +
+
+ + + {remoteInstance.get('host')} + +
+ +
+
+
+ ); +}; + +export default InstanceInfoPanel; diff --git a/app/soapbox/pages/remote_instance_page.tsx b/app/soapbox/pages/remote_instance_page.tsx index 548e0f9de4..e3488908ca 100644 --- a/app/soapbox/pages/remote_instance_page.tsx +++ b/app/soapbox/pages/remote_instance_page.tsx @@ -13,13 +13,15 @@ import { federationRestrictionsDisclosed } from 'soapbox/utils/state'; import { Layout } from '../components/ui'; interface IRemoteInstancePage { - params: { - instance: string, + params?: { + instance?: string, }, } /** Page for viewing a remote instance timeline. */ -const RemoteInstancePage: React.FC = ({ children, params: { instance: host } }) => { +const RemoteInstancePage: React.FC = ({ children, params }) => { + const host = params?.instance; + const account = useOwnAccount(); const disclosed = useAppSelector(federationRestrictionsDisclosed);