bigbuffet-rw/app/soapbox/features/ui/components/instance_info_panel.js

83 lines
2.5 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
2021-08-11 16:55:10 -07:00
import { injectIntl, defineMessages } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { makeGetRemoteInstance } from 'soapbox/selectors';
import DropdownMenu from 'soapbox/containers/dropdown_menu_container';
2021-08-11 16:55:10 -07:00
import { pinHost, unpinHost } from 'soapbox/actions/remote_timeline';
import { getSettings } from 'soapbox/actions/settings';
const getRemoteInstance = makeGetRemoteInstance();
const messages = defineMessages({
2021-08-11 16:55:10 -07:00
pinHost: { id: 'remote_instance.pin_host', defaultMessage: 'Pin {host}' },
unpinHost: { id: 'remote_instance.unpin_host', defaultMessage: 'Unpin {host}' },
});
const mapStateToProps = (state, { host }) => {
2021-08-11 16:55:10 -07:00
const settings = getSettings(state);
return {
instance: state.get('instance'),
remoteInstance: getRemoteInstance(state, host),
2021-08-11 16:55:10 -07:00
pinned: settings.getIn(['remote_timeline', 'pinnedHosts']).includes(host),
};
};
export default @connect(mapStateToProps, null, null, { forwardRef: true })
@injectIntl
class InstanceInfoPanel extends ImmutablePureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
host: PropTypes.string.isRequired,
instance: ImmutablePropTypes.map,
remoteInstance: ImmutablePropTypes.map,
2021-08-11 16:55:10 -07:00
pinned: PropTypes.bool,
};
2021-08-11 16:55:10 -07:00
handlePinHost = e => {
const { dispatch, host, pinned } = this.props;
if (!pinned) {
dispatch(pinHost(host));
} else {
dispatch(unpinHost(host));
}
}
makeMenu = () => {
2021-08-11 16:55:10 -07:00
const { intl, host, pinned } = this.props;
return [{
2021-08-11 16:55:10 -07:00
text: intl.formatMessage(pinned ? messages.unpinHost : messages.pinHost, { host }),
action: this.handlePinHost,
}];
}
render() {
2021-08-11 16:55:10 -07:00
const { remoteInstance, pinned } = this.props;
const menu = this.makeMenu();
2021-08-11 16:55:10 -07:00
const icon = pinned ? 'thumb-tack' : 'globe-w';
return (
<div className='wtf-panel instance-federation-panel'>
<div className='wtf-panel-header'>
2021-08-11 16:55:10 -07:00
<i role='img' alt={icon} className={`fa fa-${icon} wtf-panel-header__icon`} />
<span className='wtf-panel-header__label'>
2021-08-11 16:55:10 -07:00
<span>{remoteInstance.get('host')}</span>
</span>
2021-08-11 16:55:10 -07:00
<div className='wtf-panel__menu'>
<DropdownMenu items={menu} icon='ellipsis-v' size={18} direction='right' />
2021-08-11 16:55:10 -07:00
</div>
</div>
</div>
);
}
}