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' })
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));

@ -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 }),
);
});
});

@ -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,

Loading…
Cancel
Save