AccountTimeline: let it be configurable like other timelines

groups^2
Alex Gleason 2021-08-11 15:31:46 -05:00
rodzic 6665efdc1e
commit dcf7dd216f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
7 zmienionych plików z 108 dodań i 54 usunięć

Wyświetl plik

@ -127,6 +127,12 @@ export const defaultSettings = ImmutableMap({
}),
}),
account_timeline: ImmutableMap({
shows: ImmutableMap({
reblog: true,
}),
}),
trends: ImmutableMap({
show: true,
}),

Wyświetl plik

@ -0,0 +1,28 @@
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { injectIntl, FormattedMessage } from 'react-intl';
import SettingToggle from '../../notifications/components/setting_toggle';
export default @injectIntl
class ColumnSettings extends React.PureComponent {
static propTypes = {
settings: ImmutablePropTypes.map.isRequired,
onChange: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};
render() {
const { settings, onChange } = this.props;
return (
<div>
<div className='column-settings__row'>
<SettingToggle prefix='account_timeline' settings={settings} settingPath={['shows', 'reblog']} onChange={onChange} label={<FormattedMessage id='home.column_settings.show_reblogs' defaultMessage='Show reposts' />} />
</div>
</div>
);
}
}

Wyświetl plik

@ -0,0 +1,17 @@
import { connect } from 'react-redux';
import ColumnSettings from '../components/column_settings';
import { getSettings, changeSetting } from '../../../actions/settings';
const mapStateToProps = state => ({
settings: getSettings(state).get('account_timeline'),
});
const mapDispatchToProps = (dispatch) => {
return {
onChange(key, checked) {
dispatch(changeSetting(['account_timeline', ...key], checked));
},
};
};
export default connect(mapStateToProps, mapDispatchToProps)(ColumnSettings);

Wyświetl plik

@ -15,6 +15,10 @@ import MissingIndicator from 'soapbox/components/missing_indicator';
import { NavLink } from 'react-router-dom';
import { fetchPatronAccount } from '../../actions/patron';
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
import { makeGetStatusIds } from 'soapbox/selectors';
const makeMapStateToProps = () => {
const getStatusIds = makeGetStatusIds();
const mapStateToProps = (state, { params, withReplies = false }) => {
const username = params.username || '';
@ -46,8 +50,8 @@ const mapStateToProps = (state, { params, withReplies = false }) => {
accountUsername,
accountApId,
isAccount: !!state.getIn(['accounts', accountId]),
statusIds: state.getIn(['timelines', `account:${path}`, 'items'], ImmutableOrderedSet()),
featuredStatusIds: withReplies ? ImmutableOrderedSet() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], ImmutableOrderedSet()),
statusIds: getStatusIds(state, { type: `account:${path}`, prefix: 'account_timeline' }),
featuredStatusIds: withReplies ? ImmutableOrderedSet() : getStatusIds(state, { type: `account:${accountId}:pinned`, prefix: 'account_timeline' }),
isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
me,
@ -55,7 +59,10 @@ const mapStateToProps = (state, { params, withReplies = false }) => {
};
};
export default @connect(mapStateToProps)
return mapStateToProps;
};
export default @connect(makeMapStateToProps)
class AccountTimeline extends ImmutablePureComponent {
static propTypes = {

Wyświetl plik

@ -18,10 +18,6 @@ class ColumnSettings extends React.PureComponent {
return (
<div>
<div className='column-settings__row'>
<SettingToggle prefix='community_timeline' settings={settings} settingPath={['shows', 'reblog']} onChange={onChange} label={<FormattedMessage id='home.column_settings.show_reblogs' defaultMessage='Show reposts' />} />
</div>
<div className='column-settings__row'>
<SettingToggle prefix='community_timeline' settings={settings} settingPath={['shows', 'reply']} onChange={onChange} label={<FormattedMessage id='home.column_settings.show_replies' defaultMessage='Show replies' />} />
</div>

Wyświetl plik

@ -1,25 +1,10 @@
import { connect } from 'react-redux';
import StatusList from '../../../components/status_list';
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
import { createSelector } from 'reselect';
import { OrderedSet as ImmutableOrderedSet } from 'immutable';
import { makeGetStatusIds } from 'soapbox/selectors';
import { debounce } from 'lodash';
import { dequeueTimeline } from 'soapbox/actions/timelines';
import { scrollTopTimeline } from '../../../actions/timelines';
import { getSettings } from 'soapbox/actions/settings';
import { shouldFilter } from 'soapbox/utils/timelines';
const makeGetStatusIds = () => createSelector([
(state, { type }) => getSettings(state).get(type, ImmutableMap()),
(state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableOrderedSet()),
(state) => state.get('statuses'),
(state) => state.get('me'),
], (columnSettings, statusIds, statuses, me) => {
return statusIds.filter(id => {
const status = statuses.get(id);
if (!status) return true;
return !shouldFilter(status, columnSettings);
});
});
const makeMapStateToProps = () => {
const getStatusIds = makeGetStatusIds();

Wyświetl plik

@ -6,6 +6,8 @@ import {
} from 'immutable';
import { getDomain } from 'soapbox/utils/accounts';
import ConfigDB from 'soapbox/utils/config_db';
import { getSettings } from 'soapbox/actions/settings';
import { shouldFilter } from 'soapbox/utils/timelines';
const getAccountBase = (state, id) => state.getIn(['accounts', id], null);
const getAccountCounters = (state, id) => state.getIn(['accounts_counters', id], null);
@ -262,3 +264,16 @@ export const makeGetRemoteInstance = () => {
});
});
};
export const makeGetStatusIds = () => createSelector([
(state, { type, prefix }) => getSettings(state).get(prefix || type, ImmutableMap()),
(state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableOrderedSet()),
(state) => state.get('statuses'),
(state) => state.get('me'),
], (columnSettings, statusIds, statuses, me) => {
return statusIds.filter(id => {
const status = statuses.get(id);
if (!status) return true;
return !shouldFilter(status, columnSettings);
});
});