Timelines: fix dequeue, fix component propTypes

merge-requests/585/head
Alex Gleason 2021-07-08 14:52:07 -05:00
rodzic 2978745311
commit c505cde24f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
5 zmienionych plików z 30 dodań i 45 usunięć

Wyświetl plik

@ -63,42 +63,30 @@ export function updateTimelineQueue(timeline, statusId, accept) {
}; };
}; };
export function dequeueTimeline(timeline, expandFunc, optionalExpandArgs) { export function dequeueTimeline(timelineId, expandFunc, optionalExpandArgs) {
return (dispatch, getState) => { return (dispatch, getState) => {
const queuedItems = getState().getIn(['timelines', timeline, 'queuedItems'], ImmutableOrderedSet()); const state = getState();
const totalQueuedItemsCount = getState().getIn(['timelines', timeline, 'totalQueuedItemsCount'], 0); const queuedCount = state.getIn(['timelines', timelineId, 'totalQueuedItemsCount'], 0);
let shouldDispatchDequeue = true; if (queuedCount <= 0) return;
if (totalQueuedItemsCount === 0) { if (queuedCount <= MAX_QUEUED_ITEMS) {
dispatch({ type: TIMELINE_DEQUEUE, timeline: timelineId });
return; return;
} else if (totalQueuedItemsCount > 0 && totalQueuedItemsCount <= MAX_QUEUED_ITEMS) {
queuedItems.forEach(statusId => {
dispatch(updateTimeline(timeline, statusId, null));
});
} else {
if (typeof expandFunc === 'function') {
dispatch(clearTimeline(timeline));
expandFunc();
} else {
if (timeline === 'home') {
dispatch(clearTimeline(timeline));
dispatch(expandHomeTimeline(optionalExpandArgs));
} else if (timeline === 'community') {
dispatch(clearTimeline(timeline));
dispatch(expandCommunityTimeline(optionalExpandArgs));
} else {
shouldDispatchDequeue = false;
}
}
} }
if (!shouldDispatchDequeue) return; if (typeof expandFunc === 'function') {
dispatch(clearTimeline(timelineId));
dispatch({ expandFunc();
type: TIMELINE_DEQUEUE, } else {
timeline, if (timelineId === 'home') {
}); dispatch(clearTimeline(timelineId));
dispatch(expandHomeTimeline(optionalExpandArgs));
} else if (timelineId === 'community') {
dispatch(clearTimeline(timelineId));
dispatch(expandCommunityTimeline(optionalExpandArgs));
}
}
}; };
}; };

Wyświetl plik

@ -19,7 +19,7 @@ export default class StatusList extends ImmutablePureComponent {
scrollKey: PropTypes.string.isRequired, scrollKey: PropTypes.string.isRequired,
statusIds: ImmutablePropTypes.orderedSet.isRequired, statusIds: ImmutablePropTypes.orderedSet.isRequired,
lastStatusId: PropTypes.string, lastStatusId: PropTypes.string,
featuredStatusIds: ImmutablePropTypes.list, featuredStatusIds: ImmutablePropTypes.orderedSet,
onLoadMore: PropTypes.func, onLoadMore: PropTypes.func,
isLoading: PropTypes.bool, isLoading: PropTypes.bool,
isPartial: PropTypes.bool, isPartial: PropTypes.bool,

Wyświetl plik

@ -7,7 +7,7 @@ import { expandAccountFeaturedTimeline, expandAccountTimeline } from '../../acti
import StatusList from '../../components/status_list'; import StatusList from '../../components/status_list';
import LoadingIndicator from '../../components/loading_indicator'; import LoadingIndicator from '../../components/loading_indicator';
import Column from '../ui/components/column'; import Column from '../ui/components/column';
import { List as ImmutableList } from 'immutable'; import { OrderedSet as ImmutableOrderedSet } from 'immutable';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { fetchAccountIdentityProofs } from '../../actions/identity_proofs'; import { fetchAccountIdentityProofs } from '../../actions/identity_proofs';
@ -16,8 +16,6 @@ import { NavLink } from 'react-router-dom';
import { fetchPatronAccount } from '../../actions/patron'; import { fetchPatronAccount } from '../../actions/patron';
import { getSoapboxConfig } from 'soapbox/actions/soapbox'; import { getSoapboxConfig } from 'soapbox/actions/soapbox';
const emptyList = ImmutableList();
const mapStateToProps = (state, { params, withReplies = false }) => { const mapStateToProps = (state, { params, withReplies = false }) => {
const username = params.username || ''; const username = params.username || '';
const me = state.get('me'); const me = state.get('me');
@ -48,8 +46,8 @@ const mapStateToProps = (state, { params, withReplies = false }) => {
accountUsername, accountUsername,
accountApId, accountApId,
isAccount: !!state.getIn(['accounts', accountId]), isAccount: !!state.getIn(['accounts', accountId]),
statusIds: state.getIn(['timelines', `account:${path}`, 'items'], emptyList), statusIds: state.getIn(['timelines', `account:${path}`, 'items'], ImmutableOrderedSet()),
featuredStatusIds: withReplies ? ImmutableList() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], emptyList), featuredStatusIds: withReplies ? ImmutableOrderedSet() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], ImmutableOrderedSet()),
isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']), isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']), hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
me, me,
@ -63,8 +61,8 @@ class AccountTimeline extends ImmutablePureComponent {
static propTypes = { static propTypes = {
params: PropTypes.object.isRequired, params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired,
statusIds: ImmutablePropTypes.list, statusIds: ImmutablePropTypes.orderedSet,
featuredStatusIds: ImmutablePropTypes.list, featuredStatusIds: ImmutablePropTypes.orderedSet,
isLoading: PropTypes.bool, isLoading: PropTypes.bool,
hasMore: PropTypes.bool, hasMore: PropTypes.bool,
withReplies: PropTypes.bool, withReplies: PropTypes.bool,

Wyświetl plik

@ -1,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import StatusList from '../../../components/status_list'; import StatusList from '../../../components/status_list';
import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { dequeueTimeline } from 'soapbox/actions/timelines'; import { dequeueTimeline } from 'soapbox/actions/timelines';
@ -10,7 +10,7 @@ import { shouldFilter } from 'soapbox/utils/timelines';
const makeGetStatusIds = () => createSelector([ const makeGetStatusIds = () => createSelector([
(state, { type }) => getSettings(state).get(type, ImmutableMap()), (state, { type }) => getSettings(state).get(type, ImmutableMap()),
(state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableList()), (state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableOrderedSet()),
(state) => state.get('statuses'), (state) => state.get('statuses'),
(state) => state.get('me'), (state) => state.get('me'),
], (columnSettings, statusIds, statuses, me) => { ], (columnSettings, statusIds, statuses, me) => {
@ -25,7 +25,7 @@ const makeMapStateToProps = () => {
const getStatusIds = makeGetStatusIds(); const getStatusIds = makeGetStatusIds();
const mapStateToProps = (state, { timelineId }) => { const mapStateToProps = (state, { timelineId }) => {
const lastStatusId = state.getIn(['timelines', timelineId, 'items'], ImmutableList()).last(); const lastStatusId = state.getIn(['timelines', timelineId, 'items'], ImmutableOrderedSet()).last();
return { return {
statusIds: getStatusIds(state, { type: timelineId }), statusIds: getStatusIds(state, { type: timelineId }),

Wyświetl plik

@ -110,10 +110,7 @@ const updateTimelineQueue = (state, timelineId, statusId) => {
return state.update(timelineId, initialTimeline, timeline => timeline.withMutations(timeline => { return state.update(timelineId, initialTimeline, timeline => timeline.withMutations(timeline => {
timeline.set('totalQueuedItemsCount', queuedCount + 1); timeline.set('totalQueuedItemsCount', queuedCount + 1);
timeline.set('queuedItems', addStatusId(queuedIds, statusId).take(MAX_QUEUED_ITEMS));
if (queuedCount < MAX_QUEUED_ITEMS) {
timeline.set('queuedItems', addStatusId(queuedIds, statusId));
}
})); }));
}; };
@ -182,6 +179,8 @@ const removeStatusFromGroup = (state, groupId, statusId) => {
const timelineDequeue = (state, timelineId) => { const timelineDequeue = (state, timelineId) => {
return state.update(timelineId, initialTimeline, timeline => timeline.withMutations(timeline => { return state.update(timelineId, initialTimeline, timeline => timeline.withMutations(timeline => {
const queuedIds = timeline.get('queuedItems');
timeline.update('items', ids => mergeStatusIds(ids, queuedIds));
timeline.set('queuedItems', ImmutableOrderedSet()); timeline.set('queuedItems', ImmutableOrderedSet());
timeline.set('totalQueuedItemsCount', 0); timeline.set('totalQueuedItemsCount', 0);
})); }));