const noOp = () => {};
+let expandNotificationsController = new AbortController();
+
export function expandNotifications({ maxId, forceLoad } = {}, done = noOp) {
return (dispatch, getState) => {
const activeFilter = getState().getIn(['settings', 'notifications', 'quickFilter', 'active']);
const notifications = getState().get('notifications');
const isLoadingMore = !!maxId;
- if (notifications.get('isLoading') && !forceLoad) {
- done();
- return;
+ if (notifications.get('isLoading')) {
+ if (forceLoad) {
+ expandNotificationsController.abort();
+ expandNotificationsController = new AbortController();
+ } else {
+ done();
+ return;
+ }
}
const params = {
dispatch(expandNotificationsRequest(isLoadingMore));
- api(getState).get('/api/v1/notifications', { params }).then(response => {
+ api(getState).get('/api/v1/notifications', { params, signal: expandNotificationsController.signal }).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(importFetchedAccounts(response.data.map(item => item.account)));
type: NOTIFICATIONS_EXPAND_FAIL,
error,
skipLoading: !isLoadingMore,
- skipAlert: !isLoadingMore,
+ skipAlert: !isLoadingMore || error.name === 'AbortError',
};
};