From 6961309b8563661cdd7cd3d3544400619c155715 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 11 Aug 2021 18:55:10 -0500 Subject: [PATCH] RemoteTimeline: allow pinning hosts --- .../ui/components/instance_info_panel.js | 48 ++++++++++--------- app/soapbox/pages/remote_instance_page.js | 4 +- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/soapbox/features/ui/components/instance_info_panel.js b/app/soapbox/features/ui/components/instance_info_panel.js index 7c677ca4c..8a42fbb9b 100644 --- a/app/soapbox/features/ui/components/instance_info_panel.js +++ b/app/soapbox/features/ui/components/instance_info_panel.js @@ -4,28 +4,27 @@ import React from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; -import { injectIntl, defineMessages, FormattedMessage } from 'react-intl'; +import { injectIntl, defineMessages } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { makeGetRemoteInstance } from 'soapbox/selectors'; -import InstanceRestrictions from 'soapbox/features/federation_restrictions/components/instance_restrictions'; import DropdownMenu from 'soapbox/containers/dropdown_menu_container'; -import { openModal } from 'soapbox/actions/modal'; -import { isAdmin } from 'soapbox/utils/accounts'; +import { pinHost, unpinHost } from 'soapbox/actions/remote_timeline'; +import { getSettings } from 'soapbox/actions/settings'; const getRemoteInstance = makeGetRemoteInstance(); const messages = defineMessages({ - editFederation: { id: 'remote_instance.edit_federation', defaultMessage: 'Edit federation' }, + pinHost: { id: 'remote_instance.pin_host', defaultMessage: 'Pin {host}' }, + unpinHost: { id: 'remote_instance.unpin_host', defaultMessage: 'Unpin {host}' }, }); const mapStateToProps = (state, { host }) => { - const me = state.get('me'); - const account = state.getIn(['accounts', me]); + const settings = getSettings(state); return { instance: state.get('instance'), remoteInstance: getRemoteInstance(state, host), - isAdmin: isAdmin(account), + pinned: settings.getIn(['remote_timeline', 'pinnedHosts']).includes(host), }; }; @@ -38,40 +37,43 @@ class InstanceInfoPanel extends ImmutablePureComponent { host: PropTypes.string.isRequired, instance: ImmutablePropTypes.map, remoteInstance: ImmutablePropTypes.map, - isAdmin: PropTypes.bool, + pinned: PropTypes.bool, }; - handleEditFederation = e => { - const { dispatch, host } = this.props; - dispatch(openModal('EDIT_FEDERATION', { host })); + handlePinHost = e => { + const { dispatch, host, pinned } = this.props; + + if (!pinned) { + dispatch(pinHost(host)); + } else { + dispatch(unpinHost(host)); + } } makeMenu = () => { - const { intl } = this.props; + const { intl, host, pinned } = this.props; return [{ - text: intl.formatMessage(messages.editFederation), - action: this.handleEditFederation, + text: intl.formatMessage(pinned ? messages.unpinHost : messages.pinHost, { host }), + action: this.handlePinHost, }]; } render() { - const { remoteInstance, isAdmin } = this.props; + const { remoteInstance, pinned } = this.props; const menu = this.makeMenu(); + const icon = pinned ? 'thumb-tack' : 'globe-w'; return (
- + - + {remoteInstance.get('host')} - {isAdmin &&
+
-
} -
-
- +
); diff --git a/app/soapbox/pages/remote_instance_page.js b/app/soapbox/pages/remote_instance_page.js index 4620c7a40..bf2b9f04c 100644 --- a/app/soapbox/pages/remote_instance_page.js +++ b/app/soapbox/pages/remote_instance_page.js @@ -39,8 +39,8 @@ class RemoteInstancePage extends ImmutablePureComponent {
- - {(disclosed || isAdmin) && } + + {(disclosed || isAdmin) && }