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

[38081] Never mix in-app facets and unreadcount

Oliver Günther8faffca9d7ae
diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts
index 28c61d4d82a..909828e8e1a 100644
--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts
+++ b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts
@@ -6,7 +6,7 @@ import { InAppNotificationsStore, InAppNotificationsState } from './in-app-notif
@Injectable({ providedIn: 'root' })
export class InAppNotificationsQuery extends QueryEntity<InAppNotificationsState> {
/** Get the number of unread items */
- unreadCount$ = this.select('count');
+ unreadCount$ = this.select('unreadCount');
/** Do we have any unread items? */
hasUnread$ = this.unreadCount$.pipe(map((count) => count > 0));
diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts
index 864f7bc6707..d77e0fd7648 100644
--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts
+++ b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
-import { applyTransaction, ID, transaction } from '@datorama/akita';
+import { applyTransaction, ID } from '@datorama/akita';
import { Observable } from 'rxjs';
import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';
import { map, switchMap, tap } from 'rxjs/operators';
@@ -36,7 +36,7 @@ export class InAppNotificationsService {
(events) => {
applyTransaction(() => {
this.store.set(events._embedded.elements);
- this.store.update({ count: events.total, notShowing: events.total - events.count });
+ this.store.update({ notShowing: events.total - events.count });
});
},
(error) => {
@@ -55,27 +55,17 @@ export class InAppNotificationsService {
.unread({ pageSize: 0 })
.pipe(
map((events) => events.total),
- tap((count) => this.store.update({ count })),
+ tap((unreadCount) => {
+ this.store.update({ unreadCount });
+ }),
);
}
- @transaction()
- add(inAppNotification:InAppNotification):void {
- this.store.add(inAppNotification);
- this.store.update((state) => ({ ...state, count: state.count + 1 }));
- }
-
update(id:ID, inAppNotification:Partial<InAppNotification>):void {
this.store.update(id, inAppNotification);
}
- @transaction()
- remove(id:ID):void {
- this.store.remove(id);
- this.store.update((state) => ({ ...state, count: state.count + 1 }));
- }
-
- setActiveFacet(facet:string) {
+ setActiveFacet(facet:string):void {
this.store.update((state) => ({ ...state, activeFacet: facet }));
}
@@ -89,7 +79,7 @@ export class InAppNotificationsService {
.subscribe(() => {
applyTransaction(() => {
this.store.update(null, { readIAN: true });
- this.store.update({ count: 0 });
+ this.store.update({ unreadCount: 0 });
});
});
}
@@ -100,7 +90,7 @@ export class InAppNotificationsService {
return href && HalResource.matchFromLink(href, 'work_packages');
});
- this
+ void this
.apiV3Service
.work_packages
.requireAll(_.compact(wpIds));
@@ -140,7 +130,7 @@ export class InAppNotificationsService {
},
);
this.store.update(
- ({ count }) => ({ count: count - 1 }),
+ ({ unreadCount }) => ({ unreadCount: unreadCount - 1 }),
);
});
});
diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.ts
index c6504bbe744..796100e0903 100644
--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.ts
+++ b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.ts
@@ -3,14 +3,15 @@ import { EntityState, EntityStore, StoreConfig } from '@datorama/akita';
import { InAppNotification } from './in-app-notification.model';
export interface InAppNotificationsState extends EntityState<InAppNotification> {
- count:number;
+ /** The entities in the store might not all be unread so we keep separate count */
+ unreadCount:number;
activeFacet:string;
expanded:boolean;
}
export function createInitialState():InAppNotificationsState {
return {
- count: 0,
+ unreadCount: 0,
notShowing: 0,
activeFacet: 'unread',
expanded: false,