Skip to content

Commit

Permalink
119602: Compare notifications by id to correctly update store
Browse files Browse the repository at this point in the history
  • Loading branch information
AAwouters committed Nov 29, 2024
1 parent c38352e commit cdec488
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {

import { select, Store } from '@ngrx/store';
import { BehaviorSubject, Subscription, take } from 'rxjs';
import difference from 'lodash/difference';

import { NotificationsService } from '../notifications.service';
import { AppState } from '../../../app.reducer';
Expand All @@ -23,6 +22,7 @@ import {
AccessibilitySetting
} from '../../../accessibility/accessibility-settings.service';
import cloneDeep from 'lodash/cloneDeep';
import differenceWith from 'lodash/differenceWith';

@Component({
selector: 'ds-notifications-board',
Expand Down Expand Up @@ -69,13 +69,13 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
this.notifications = [];
} else if (state.length > this.notifications.length) {
// Add
const newElem = difference(state, this.notifications);
const newElem = differenceWith(state, this.notifications, this.byId);
newElem.forEach((notification) => {
this.add(notification);
});
} else {
// Remove
const delElem = difference(this.notifications, state);
const delElem = differenceWith(this.notifications, state, this.byId);
delElem.forEach((notification) => {
this.notifications = this.notifications.filter((item: INotification) => item.id !== notification.id);

Expand All @@ -85,6 +85,9 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
});
}

private byId = (notificationA: INotification, notificationB: INotification) =>
notificationA.id === notificationB.id;

// Add the new notification to the notification array
add(item: INotification): void {
const toBlock: boolean = this.block(item);
Expand Down

0 comments on commit cdec488

Please sign in to comment.