Merge pull request #9502 from opf/fix/38081/keep-unread-count-separate

[38081] Never mix in-app facets and unreadcount
pull/9504/head
Henriette Darge 3 years ago committed by GitHub
commit 5883c6eccd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts
  2. 28
      frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts
  3. 5
      frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.ts

@ -6,7 +6,7 @@ import { InAppNotificationsStore, InAppNotificationsState } from './in-app-notif
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class InAppNotificationsQuery extends QueryEntity<InAppNotificationsState> { export class InAppNotificationsQuery extends QueryEntity<InAppNotificationsState> {
/** Get the number of unread items */ /** Get the number of unread items */
unreadCount$ = this.select('count'); unreadCount$ = this.select('unreadCount');
/** Do we have any unread items? */ /** Do we have any unread items? */
hasUnread$ = this.unreadCount$.pipe(map((count) => count > 0)); hasUnread$ = this.unreadCount$.pipe(map((count) => count > 0));

@ -1,5 +1,5 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { applyTransaction, ID, transaction } from '@datorama/akita'; import { applyTransaction, ID } from '@datorama/akita';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { APIV3Service } from 'core-app/core/apiv3/api-v3.service'; import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';
import { map, switchMap, tap } from 'rxjs/operators'; import { map, switchMap, tap } from 'rxjs/operators';
@ -36,7 +36,7 @@ export class InAppNotificationsService {
(events) => { (events) => {
applyTransaction(() => { applyTransaction(() => {
this.store.set(events._embedded.elements); 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) => { (error) => {
@ -55,27 +55,17 @@ export class InAppNotificationsService {
.unread({ pageSize: 0 }) .unread({ pageSize: 0 })
.pipe( .pipe(
map((events) => events.total), 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 { update(id:ID, inAppNotification:Partial<InAppNotification>):void {
this.store.update(id, inAppNotification); this.store.update(id, inAppNotification);
} }
@transaction() setActiveFacet(facet:string):void {
remove(id:ID):void {
this.store.remove(id);
this.store.update((state) => ({ ...state, count: state.count + 1 }));
}
setActiveFacet(facet:string) {
this.store.update((state) => ({ ...state, activeFacet: facet })); this.store.update((state) => ({ ...state, activeFacet: facet }));
} }
@ -89,7 +79,7 @@ export class InAppNotificationsService {
.subscribe(() => { .subscribe(() => {
applyTransaction(() => { applyTransaction(() => {
this.store.update(null, { readIAN: true }); 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'); return href && HalResource.matchFromLink(href, 'work_packages');
}); });
this void this
.apiV3Service .apiV3Service
.work_packages .work_packages
.requireAll(_.compact(wpIds)); .requireAll(_.compact(wpIds));
@ -140,7 +130,7 @@ export class InAppNotificationsService {
}, },
); );
this.store.update( this.store.update(
({ count }) => ({ count: count - 1 }), ({ unreadCount }) => ({ unreadCount: unreadCount - 1 }),
); );
}); });
}); });

@ -3,14 +3,15 @@ import { EntityState, EntityStore, StoreConfig } from '@datorama/akita';
import { InAppNotification } from './in-app-notification.model'; import { InAppNotification } from './in-app-notification.model';
export interface InAppNotificationsState extends EntityState<InAppNotification> { 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; activeFacet:string;
expanded:boolean; expanded:boolean;
} }
export function createInitialState():InAppNotificationsState { export function createInitialState():InAppNotificationsState {
return { return {
count: 0, unreadCount: 0,
notShowing: 0, notShowing: 0,
activeFacet: 'unread', activeFacet: 'unread',
expanded: false, expanded: false,

Loading…
Cancel
Save