Timelines: truncate on dequeue if scrolled to the top

merge-requests/585/head
Alex Gleason 2021-07-08 15:30:18 -05:00
rodzic dd6746c3d7
commit f0fa5e6945
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 14 dodań i 2 usunięć

Wyświetl plik

@ -25,6 +25,9 @@ import {
} from 'immutable';
import { GROUP_REMOVE_STATUS_SUCCESS } from '../actions/groups';
const TRUNCATE_LIMIT = 40;
const TRUNCATE_SIZE = 20;
const initialState = ImmutableMap();
const initialTimeline = ImmutableMap({
@ -55,6 +58,8 @@ const truncate = (items, truncateLimit, newSize) => (
items.size > truncateLimit ? items.take(newSize) : items
);
const truncateIds = items => truncate(items, TRUNCATE_LIMIT, TRUNCATE_SIZE);
const setLoading = (state, timelineId, loading) => {
return state.update(timelineId, initialTimeline, timeline => timeline.set('isLoading', loading));
};
@ -98,7 +103,7 @@ const updateTimeline = (state, timelineId, statusId) => {
return state.update(timelineId, initialTimeline, timeline => timeline.withMutations(timeline => {
if (top) {
// For performance, truncate items if user is scrolled to the top
timeline.set('items', truncate(newIds, 40, 20));
timeline.set('items', truncateIds(newIds));
} else {
timeline.set('unread', unread + 1);
timeline.set('items', newIds);
@ -184,9 +189,16 @@ const removeStatusFromGroup = (state, groupId, statusId) => {
};
const timelineDequeue = (state, timelineId) => {
const top = state.getIn([timelineId, 'top']);
return state.update(timelineId, initialTimeline, timeline => timeline.withMutations(timeline => {
const queuedIds = timeline.get('queuedItems');
timeline.update('items', ids => mergeStatusIds(ids, queuedIds));
timeline.update('items', ids => {
const newIds = mergeStatusIds(ids, queuedIds);
return top ? truncateIds(newIds) : newIds;
});
timeline.set('queuedItems', ImmutableOrderedSet());
timeline.set('totalQueuedItemsCount', 0);
}));