diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts index 08ef206380..79475327c8 100644 --- a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts +++ b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts @@ -19,7 +19,10 @@ import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type'; import { HttpClient } from '@angular/common/http'; import { InAppNotificationsQuery } from 'core-app/core/state/in-app-notifications/in-app-notifications.query'; import { Apiv3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface'; -import { collectionKey } from 'core-app/core/state/collection-store.type'; +import { + collectionKey, + CollectionResponse, +} from 'core-app/core/state/collection-store.type'; import { markNotificationsAsRead, notificationsMarkedRead, @@ -81,6 +84,36 @@ export class InAppNotificationsService extends UntilDestroyedMixin { this.store.update(id, inAppNotification); } + modifyCollection(params:Apiv3ListParameters, callback:(collection:ID[]) => ID[]) { + const key = collectionKey(params); + this.store.update(({ collections }) => ( + { + collections: { + ...collections, + [key]: { + ...collections[key], + ids: [...callback(collections[key]?.ids || [])], + }, + }, + } + )); + } + + removeFromCollection(params:Apiv3ListParameters, ids:ID[]):void { + const key = collectionKey(params); + this.store.update(({ collections }) => ( + { + collections: { + ...collections, + [key]: { + ...collections[key], + ids: (collections[key]?.ids || []).filter((id) => !ids.includes(id)), + }, + }, + } + )); + } + markAsRead(notifications:ID[]):Observable { return this .apiV3Service diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts index c953c3c078..7ab14bc5e7 100644 --- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts +++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts @@ -89,7 +89,7 @@ export class IanCenterService extends UntilDestroyedMixin { } markAllAsRead():void { - selectCollection$(this.ianService, this.store.getValue().params) + selectCollection$(this.ianService, this.params) .pipe( take(1), ) @@ -103,7 +103,11 @@ export class IanCenterService extends UntilDestroyedMixin { */ @EffectCallback(notificationsMarkedRead) private reloadOnNotificationRead(action:ReturnType) { - if (action.caller !== this) { + if (action.caller === this) { + this + .ianService + .removeFromCollection(this.params, action.notifications); + } else { this.reload(); } }