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 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 (
<div className='wtf-panel instance-federation-panel'>
<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><FormattedMessage id='remote_instance.federation_panel.heading' defaultMessage='Federation Restrictions' /></span>
<span>{remoteInstance.get('host')}</span>
</span>
{isAdmin && <div className='wtf-panel__menu'>
<div className='wtf-panel__menu'>
<DropdownMenu items={menu} icon='ellipsis-v' size={18} direction='right' />
</div>}
</div>
<div className='wtf-panel__content'>
<InstanceRestrictions remoteInstance={remoteInstance} />
</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__inner'>
<InstanceModerationPanel host={host} />
{(disclosed || isAdmin) && <InstanceInfoPanel host={host} />}
<InstanceInfoPanel host={host} />
{(disclosed || isAdmin) && <InstanceModerationPanel host={host} />}
</div>
</div>

Loading…
Cancel
Save