[Glitch] Fix quickly switching notification filters resulting in empty or incorrect list

Port ef1b55caa6 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
th-downstream
Claire 2 years ago
parent e0055fdcf7
commit 58261f2888

@ -158,13 +158,13 @@ const excludeTypesFromFilter = filter => {
const noOp = () => {}; const noOp = () => {};
export function expandNotifications({ maxId } = {}, done = noOp) { export function expandNotifications({ maxId, forceLoad } = {}, done = noOp) {
return (dispatch, getState) => { return (dispatch, getState) => {
const activeFilter = getState().getIn(['settings', 'notifications', 'quickFilter', 'active']); const activeFilter = getState().getIn(['settings', 'notifications', 'quickFilter', 'active']);
const notifications = getState().get('notifications'); const notifications = getState().get('notifications');
const isLoadingMore = !!maxId; const isLoadingMore = !!maxId;
if (notifications.get('isLoading')) { if (notifications.get('isLoading') && !forceLoad) {
done(); done();
return; return;
} }
@ -343,7 +343,7 @@ export function setFilter (filterType) {
path: ['notifications', 'quickFilter', 'active'], path: ['notifications', 'quickFilter', 'active'],
value: filterType, value: filterType,
}); });
dispatch(expandNotifications()); dispatch(expandNotifications({ forceLoad: true }));
dispatch(saveSettings()); dispatch(saveSettings());
}; };
}; };

@ -43,7 +43,7 @@ const initialState = ImmutableMap({
unread: 0, unread: 0,
lastReadId: '0', lastReadId: '0',
readMarkerId: '0', readMarkerId: '0',
isLoading: false, isLoading: 0,
cleaningMode: false, cleaningMode: false,
isTabVisible: true, isTabVisible: true,
browserSupport: false, browserSupport: false,
@ -121,7 +121,7 @@ const expandNormalizedNotifications = (state, notifications, next, isLoadingRece
} }
} }
mutable.set('isLoading', false); mutable.update('isLoading', (nbLoading) => nbLoading - 1);
}); });
}; };
@ -249,10 +249,10 @@ export default function notifications(state = initialState, action) {
return state.update('items', list => state.get('pendingItems').concat(list.take(40))).set('pendingItems', ImmutableList()).set('unread', 0); return state.update('items', list => state.get('pendingItems').concat(list.take(40))).set('pendingItems', ImmutableList()).set('unread', 0);
case NOTIFICATIONS_EXPAND_REQUEST: case NOTIFICATIONS_EXPAND_REQUEST:
case NOTIFICATIONS_DELETE_MARKED_REQUEST: case NOTIFICATIONS_DELETE_MARKED_REQUEST:
return state.set('isLoading', true); return state.set('isLoading', (nbLoading) => nbLoading + 1);
case NOTIFICATIONS_DELETE_MARKED_FAIL: case NOTIFICATIONS_DELETE_MARKED_FAIL:
case NOTIFICATIONS_EXPAND_FAIL: case NOTIFICATIONS_EXPAND_FAIL:
return state.set('isLoading', false); return state.set('isLoading', (nbLoading) => nbLoading - 1);
case NOTIFICATIONS_FILTER_SET: case NOTIFICATIONS_FILTER_SET:
return state.set('items', ImmutableList()).set('hasMore', true); return state.set('items', ImmutableList()).set('hasMore', true);
case NOTIFICATIONS_SCROLL_TOP: case NOTIFICATIONS_SCROLL_TOP:
@ -287,7 +287,7 @@ export default function notifications(state = initialState, action) {
return markForDelete(state, action.id, action.yes); return markForDelete(state, action.id, action.yes);
case NOTIFICATIONS_DELETE_MARKED_SUCCESS: case NOTIFICATIONS_DELETE_MARKED_SUCCESS:
return deleteMarkedNotifs(state).set('isLoading', false); return deleteMarkedNotifs(state).set('isLoading', (nbLoading) => nbLoading - 1);
case NOTIFICATIONS_ENTER_CLEARING_MODE: case NOTIFICATIONS_ENTER_CLEARING_MODE:
st = state.set('cleaningMode', action.yes); st = state.set('cleaningMode', action.yes);

Loading…
Cancel
Save