Allow manipulating collections without reloading

pull/9626/head
Oliver Günther 3 years ago
parent 50f233dd93
commit 6a234db808
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 35
      frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts
  2. 8
      frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts

@ -19,7 +19,10 @@ import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { InAppNotificationsQuery } from 'core-app/core/state/in-app-notifications/in-app-notifications.query'; 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 { 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 { import {
markNotificationsAsRead, markNotificationsAsRead,
notificationsMarkedRead, notificationsMarkedRead,
@ -81,6 +84,36 @@ export class InAppNotificationsService extends UntilDestroyedMixin {
this.store.update(id, inAppNotification); 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<unknown> { markAsRead(notifications:ID[]):Observable<unknown> {
return this return this
.apiV3Service .apiV3Service

@ -89,7 +89,7 @@ export class IanCenterService extends UntilDestroyedMixin {
} }
markAllAsRead():void { markAllAsRead():void {
selectCollection$(this.ianService, this.store.getValue().params) selectCollection$(this.ianService, this.params)
.pipe( .pipe(
take(1), take(1),
) )
@ -103,7 +103,11 @@ export class IanCenterService extends UntilDestroyedMixin {
*/ */
@EffectCallback(notificationsMarkedRead) @EffectCallback(notificationsMarkedRead)
private reloadOnNotificationRead(action:ReturnType<typeof notificationsMarkedRead>) { private reloadOnNotificationRead(action:ReturnType<typeof notificationsMarkedRead>) {
if (action.caller !== this) { if (action.caller === this) {
this
.ianService
.removeFromCollection(this.params, action.notifications);
} else {
this.reload(); this.reload();
} }
} }

Loading…
Cancel
Save