RemoteTimeline: allow pinning hosts

merge-requests/670/head
Alex Gleason 3 years ago
parent 9e12e978d8
commit 6961309b85
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -4,28 +4,27 @@ import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; 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 ImmutablePureComponent from 'react-immutable-pure-component';
import { makeGetRemoteInstance } from 'soapbox/selectors'; import { makeGetRemoteInstance } from 'soapbox/selectors';
import InstanceRestrictions from 'soapbox/features/federation_restrictions/components/instance_restrictions';
import DropdownMenu from 'soapbox/containers/dropdown_menu_container'; import DropdownMenu from 'soapbox/containers/dropdown_menu_container';
import { openModal } from 'soapbox/actions/modal'; import { pinHost, unpinHost } from 'soapbox/actions/remote_timeline';
import { isAdmin } from 'soapbox/utils/accounts'; import { getSettings } from 'soapbox/actions/settings';
const getRemoteInstance = makeGetRemoteInstance(); const getRemoteInstance = makeGetRemoteInstance();
const messages = defineMessages({ 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 mapStateToProps = (state, { host }) => {
const me = state.get('me'); const settings = getSettings(state);
const account = state.getIn(['accounts', me]);
return { return {
instance: state.get('instance'), instance: state.get('instance'),
remoteInstance: getRemoteInstance(state, host), 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, host: PropTypes.string.isRequired,
instance: ImmutablePropTypes.map, instance: ImmutablePropTypes.map,
remoteInstance: ImmutablePropTypes.map, remoteInstance: ImmutablePropTypes.map,
isAdmin: PropTypes.bool, pinned: PropTypes.bool,
}; };
handleEditFederation = e => { handlePinHost = e => {
const { dispatch, host } = this.props; const { dispatch, host, pinned } = this.props;
dispatch(openModal('EDIT_FEDERATION', { host }));
if (!pinned) {
dispatch(pinHost(host));
} else {
dispatch(unpinHost(host));
}
} }
makeMenu = () => { makeMenu = () => {
const { intl } = this.props; const { intl, host, pinned } = this.props;
return [{ return [{
text: intl.formatMessage(messages.editFederation), text: intl.formatMessage(pinned ? messages.unpinHost : messages.pinHost, { host }),
action: this.handleEditFederation, action: this.handlePinHost,
}]; }];
} }
render() { render() {
const { remoteInstance, isAdmin } = this.props; const { remoteInstance, pinned } = this.props;
const menu = this.makeMenu(); const menu = this.makeMenu();
const icon = pinned ? 'thumb-tack' : 'globe-w';
return ( return (
<div className='wtf-panel instance-federation-panel'> <div className='wtf-panel instance-federation-panel'>
<div className='wtf-panel-header'> <div className='wtf-panel-header'>
<i role='img' alt='gavel' className='fa fa-gavel wtf-panel-header__icon' /> <i role='img' alt={icon} className={`fa fa-${icon} wtf-panel-header__icon`} />
<span className='wtf-panel-header__label'> <span className='wtf-panel-header__label'>
<span><FormattedMessage id='remote_instance.federation_panel.heading' defaultMessage='Federation Restrictions' /></span> <span>{remoteInstance.get('host')}</span>
</span> </span>
{isAdmin && <div className='wtf-panel__menu'> <div className='wtf-panel__menu'>
<DropdownMenu items={menu} icon='ellipsis-v' size={18} direction='right' /> <DropdownMenu items={menu} icon='ellipsis-v' size={18} direction='right' />
</div>} </div>
</div>
<div className='wtf-panel__content'>
<InstanceRestrictions remoteInstance={remoteInstance} />
</div> </div>
</div> </div>
); );

@ -39,8 +39,8 @@ class RemoteInstancePage extends ImmutablePureComponent {
<div className='columns-area__panels__pane columns-area__panels__pane--left'> <div className='columns-area__panels__pane columns-area__panels__pane--left'>
<div className='columns-area__panels__pane__inner'> <div className='columns-area__panels__pane__inner'>
<InstanceModerationPanel host={host} /> <InstanceInfoPanel host={host} />
{(disclosed || isAdmin) && <InstanceInfoPanel host={host} />} {(disclosed || isAdmin) && <InstanceModerationPanel host={host} />}
</div> </div>
</div> </div>

Loading…
Cancel
Save