Skip to content

Commit

Permalink
Keep track of deleted notifications, so re-fetching doesn't restore them
Browse files Browse the repository at this point in the history
  • Loading branch information
miko committed Jan 16, 2024
1 parent a030230 commit 5302787
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions flow-typed/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ declare type DoDismissError = {
declare type NotificationState = {
notifications: Array<Notification>,
notificationsFiltered: Array<Notification>,
deletedNotificationIds: Array<number>,
notificationCategories: any,
fetchingNotifications: boolean,
errors: Array<ErrorNotification>,
Expand Down
14 changes: 11 additions & 3 deletions ui/redux/reducers/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { handleActions } from 'util/redux-utils';
const defaultState: NotificationState = {
notifications: [],
notificationsFiltered: [],
deletedNotificationIds: [],
notificationCategories: undefined,
fetchingNotifications: false,
toasts: [],
Expand Down Expand Up @@ -56,17 +57,23 @@ export default handleActions(
};
},
[ACTIONS.NOTIFICATION_LIST_COMPLETED]: (state, action) => {
const { deletedNotificationIds } = state;
const { filterRule, newNotifications } = action.data;

const deleteIds = (list, ids) => {
return list.filter((n) => !ids.includes(n.id));
};

if (filterRule) {
return {
...state,
notificationsFiltered: newNotifications,
notificationsFiltered: deleteIds(newNotifications, deletedNotificationIds),
fetchingNotifications: false,
};
} else {
return {
...state,
notifications: newNotifications,
notifications: deleteIds(newNotifications, deletedNotificationIds),
fetchingNotifications: false,
};
}
Expand Down Expand Up @@ -133,7 +140,7 @@ export default handleActions(
};
},
[ACTIONS.NOTIFICATION_DELETE_COMPLETED]: (state, action) => {
const { notifications, notificationsFiltered } = state;
const { notifications, notificationsFiltered, deletedNotificationIds } = state;
const { notificationId } = action.data;

const deleteId = (list, id) => {
Expand All @@ -144,6 +151,7 @@ export default handleActions(
...state,
notifications: deleteId(notifications, notificationId),
notificationsFiltered: deleteId(notificationsFiltered, notificationId),
deletedNotificationIds: deletedNotificationIds.concat(notificationId),
};
},

Expand Down

0 comments on commit 5302787

Please sign in to comment.