Merge branch 'pinned-remote-hosts' into 'develop'
Pinned remote hosts See merge request soapbox-pub/soapbox-fe!670
This commit is contained in:
commit
3596fd39b0
|
@ -0,0 +1,24 @@
|
|||
import { getSettings, changeSetting } from 'soapbox/actions/settings';
|
||||
|
||||
const getPinnedHosts = state => {
|
||||
const settings = getSettings(state);
|
||||
return settings.getIn(['remote_timeline', 'pinnedHosts']);
|
||||
};
|
||||
|
||||
export function pinHost(host) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const pinnedHosts = getPinnedHosts(state);
|
||||
|
||||
return dispatch(changeSetting(['remote_timeline', 'pinnedHosts'], pinnedHosts.add(host)));
|
||||
};
|
||||
}
|
||||
|
||||
export function unpinHost(host) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const pinnedHosts = getPinnedHosts(state);
|
||||
|
||||
return dispatch(changeSetting(['remote_timeline', 'pinnedHosts'], pinnedHosts.delete(host)));
|
||||
};
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import { debounce } from 'lodash';
|
||||
import { showAlertForError } from './alerts';
|
||||
import { patchMe } from 'soapbox/actions/me';
|
||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet } from 'immutable';
|
||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||
import uuid from '../uuid';
|
||||
import { createSelector } from 'reselect';
|
||||
|
@ -143,6 +143,10 @@ export const defaultSettings = ImmutableMap({
|
|||
ImmutableMap({ id: 'HOME', uuid: uuid(), params: {} }),
|
||||
ImmutableMap({ id: 'NOTIFICATIONS', uuid: uuid(), params: {} }),
|
||||
]),
|
||||
|
||||
remote_timeline: ImmutableMap({
|
||||
pinnedHosts: ImmutableOrderedSet(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const getSettings = createSelector([
|
||||
|
|
|
@ -7,6 +7,7 @@ import Column from '../../components/column';
|
|||
import ColumnSettingsContainer from './containers/column_settings_container';
|
||||
import HomeColumnHeader from '../../components/home_column_header';
|
||||
import Accordion from 'soapbox/features/ui/components/accordion';
|
||||
import PinnedHostsPicker from '../remote_timeline/components/pinned_hosts_picker';
|
||||
import { expandPublicTimeline } from '../../actions/timelines';
|
||||
import { connectPublicStream } from '../../actions/streaming';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
@ -101,6 +102,7 @@ class CommunityTimeline extends React.PureComponent {
|
|||
<HomeColumnHeader activeItem='fediverse' active={hasUnread} >
|
||||
<ColumnSettingsContainer />
|
||||
</HomeColumnHeader>
|
||||
<PinnedHostsPicker />
|
||||
{showExplanationBox && <div className='explanation-box'>
|
||||
<Accordion
|
||||
headline={<FormattedMessage id='fediverse_tab.explanation_box.title' defaultMessage='What is the Fediverse?' />}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
'use strict';
|
||||
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import classNames from 'classnames';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { getSettings } from 'soapbox/actions/settings';
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const settings = getSettings(state);
|
||||
|
||||
return {
|
||||
pinnedHosts: settings.getIn(['remote_timeline', 'pinnedHosts']),
|
||||
};
|
||||
};
|
||||
|
||||
class PinnedHostPicker extends React.PureComponent {
|
||||
|
||||
static contextTypes = {
|
||||
router: PropTypes.object,
|
||||
};
|
||||
|
||||
static propTypes = {
|
||||
dispatch: PropTypes.func.isRequired,
|
||||
pinnedHosts: ImmutablePropTypes.orderedSet,
|
||||
host: PropTypes.string,
|
||||
};
|
||||
|
||||
render() {
|
||||
const { pinnedHosts, host: activeHost } = this.props;
|
||||
|
||||
if (!pinnedHosts || pinnedHosts.isEmpty()) return null;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className='pinned-hosts-picker'>
|
||||
{pinnedHosts.map(host => (
|
||||
<div className={classNames('pinned-host', { 'active': host === activeHost })} key={host}>
|
||||
<Link to={`/timeline/${host}`}>{host}</Link>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(PinnedHostPicker);
|
|
@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
|
|||
import StatusListContainer from '../ui/containers/status_list_container';
|
||||
import Column from '../../components/column';
|
||||
import HomeColumnHeader from '../../components/home_column_header';
|
||||
import PinnedHostsPicker from './components/pinned_hosts_picker';
|
||||
import IconButton from 'soapbox/components/icon_button';
|
||||
import { expandRemoteTimeline } from '../../actions/timelines';
|
||||
import { connectRemoteStream } from '../../actions/streaming';
|
||||
|
@ -84,6 +85,7 @@ class RemoteTimeline extends React.PureComponent {
|
|||
return (
|
||||
<Column label={intl.formatMessage(messages.title)}>
|
||||
<HomeColumnHeader activeItem='fediverse' active={hasUnread} />
|
||||
<PinnedHostsPicker host={instance} />
|
||||
<div className='timeline-filter-message'>
|
||||
<IconButton icon='close' onClick={this.handleCloseClick} />
|
||||
<FormattedMessage
|
||||
|
|
|
@ -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>
|
||||
);
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
'use strict';
|
||||
|
||||
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 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';
|
||||
|
||||
const getRemoteInstance = makeGetRemoteInstance();
|
||||
|
||||
const messages = defineMessages({
|
||||
editFederation: { id: 'remote_instance.edit_federation', defaultMessage: 'Edit federation' },
|
||||
});
|
||||
|
||||
const mapStateToProps = (state, { host }) => {
|
||||
const me = state.get('me');
|
||||
const account = state.getIn(['accounts', me]);
|
||||
|
||||
return {
|
||||
instance: state.get('instance'),
|
||||
remoteInstance: getRemoteInstance(state, host),
|
||||
isAdmin: isAdmin(account),
|
||||
};
|
||||
};
|
||||
|
||||
export default @connect(mapStateToProps, null, null, { forwardRef: true })
|
||||
@injectIntl
|
||||
class InstanceModerationPanel extends ImmutablePureComponent {
|
||||
|
||||
static propTypes = {
|
||||
intl: PropTypes.object.isRequired,
|
||||
host: PropTypes.string.isRequired,
|
||||
instance: ImmutablePropTypes.map,
|
||||
remoteInstance: ImmutablePropTypes.map,
|
||||
isAdmin: PropTypes.bool,
|
||||
};
|
||||
|
||||
handleEditFederation = e => {
|
||||
const { dispatch, host } = this.props;
|
||||
dispatch(openModal('EDIT_FEDERATION', { host }));
|
||||
}
|
||||
|
||||
makeMenu = () => {
|
||||
const { intl } = this.props;
|
||||
|
||||
return [{
|
||||
text: intl.formatMessage(messages.editFederation),
|
||||
action: this.handleEditFederation,
|
||||
}];
|
||||
}
|
||||
|
||||
render() {
|
||||
const { remoteInstance, isAdmin } = this.props;
|
||||
const menu = this.makeMenu();
|
||||
|
||||
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' />
|
||||
<span className='wtf-panel-header__label'>
|
||||
<span><FormattedMessage id='remote_instance.federation_panel.heading' defaultMessage='Federation Restrictions' /></span>
|
||||
</span>
|
||||
{isAdmin && <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>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ import FeaturesPanel from 'soapbox/features/ui/components/features_panel';
|
|||
import LinkFooter from 'soapbox/features/ui/components/link_footer';
|
||||
import { getFeatures } from 'soapbox/utils/features';
|
||||
import InstanceInfoPanel from 'soapbox/features/ui/components/instance_info_panel';
|
||||
import InstanceModerationPanel from 'soapbox/features/ui/components/instance_moderation_panel';
|
||||
import { federationRestrictionsDisclosed } from 'soapbox/utils/state';
|
||||
import { isAdmin } from 'soapbox/utils/accounts';
|
||||
|
||||
|
@ -38,7 +39,8 @@ class RemoteInstancePage extends ImmutablePureComponent {
|
|||
|
||||
<div className='columns-area__panels__pane columns-area__panels__pane--left'>
|
||||
<div className='columns-area__panels__pane__inner'>
|
||||
{(disclosed || isAdmin) && <InstanceInfoPanel host={host} />}
|
||||
<InstanceInfoPanel host={host} />
|
||||
{(disclosed || isAdmin) && <InstanceModerationPanel host={host} />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -27,3 +27,48 @@
|
|||
padding-right: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.pinned-hosts-picker {
|
||||
margin-left: 10px;
|
||||
display: inline-flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.pinned-host {
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
.pinned-host {
|
||||
background: var(--background-color);
|
||||
|
||||
&:hover {
|
||||
background: var(--brand-color--faint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pinned-host {
|
||||
background: var(--background-color);
|
||||
border-radius: 999px;
|
||||
transition: 0.2s;
|
||||
|
||||
&.active {
|
||||
background: var(--brand-color--faint);
|
||||
|
||||
a {
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
display: block;
|
||||
color: var(--primary-text-color);
|
||||
text-decoration: none;
|
||||
padding: 5px 11px;
|
||||
max-width: 115px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue