mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-22 17:35:40 +01:00
Fix not being able to load more notifications after trimming (#31652)
This commit is contained in:
parent
491033c86c
commit
c1795ee963
1 changed files with 24 additions and 1 deletions
|
@ -248,8 +248,9 @@ function processNewNotification(
|
|||
}
|
||||
|
||||
function trimNotifications(state: NotificationGroupsState) {
|
||||
if (state.scrolledToTop) {
|
||||
if (state.scrolledToTop && state.groups.length > NOTIFICATIONS_TRIM_LIMIT) {
|
||||
state.groups.splice(NOTIFICATIONS_TRIM_LIMIT);
|
||||
ensureTrailingGap(state.groups);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -400,6 +401,28 @@ function ensureLeadingGap(
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure the groups list ends with a gap suitable for loading more, mutating it to append one if needed
|
||||
function ensureTrailingGap(
|
||||
groups: NotificationGroupsState['groups'],
|
||||
): NotificationGap {
|
||||
const groupOrGap = groups.at(-1);
|
||||
|
||||
if (groupOrGap?.type === 'gap') {
|
||||
// We're expecting older notifications, so discard sinceId if it's set
|
||||
groupOrGap.sinceId = undefined;
|
||||
|
||||
return groupOrGap;
|
||||
} else {
|
||||
const gap: NotificationGap = {
|
||||
type: 'gap',
|
||||
maxId: groupOrGap?.page_min_id,
|
||||
};
|
||||
|
||||
groups.push(gap);
|
||||
return gap;
|
||||
}
|
||||
}
|
||||
|
||||
export const notificationGroupsReducer = createReducer<NotificationGroupsState>(
|
||||
initialState,
|
||||
(builder) => {
|
||||
|
|
Loading…
Reference in a new issue