Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Allow manipulating collections without reloading

Oliver Günther6a234db808d9
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 08ef206380a..79475327c86 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<unknown> {
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 c953c3c0780..7ab14bc5e71 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<typeof notificationsMarkedRead>) {
- if (action.caller !== this) {
+ if (action.caller === this) {
+ this
+ .ianService
+ .removeFromCollection(this.params, action.notifications);
+ } else {
this.reload();
}
}