From 05a90d6fbdba0057fe7145f7eff928ec357fedb1 Mon Sep 17 00:00:00 2001 From: Sofia Papacharalampous Date: Mon, 20 May 2024 11:37:42 +0300 Subject: [PATCH] update status on in-app-notificatons-dialog "read all" --- .../src/app/ui/navbar/navbar.component.ts | 3 + ...p-notification-listing-dialog.component.ts | 73 ++++++++++++------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/dmp-frontend/src/app/ui/navbar/navbar.component.ts b/dmp-frontend/src/app/ui/navbar/navbar.component.ts index 5f3170065..32b996f30 100644 --- a/dmp-frontend/src/app/ui/navbar/navbar.component.ts +++ b/dmp-frontend/src/app/ui/navbar/navbar.component.ts @@ -348,6 +348,9 @@ export class NavbarComponent extends BaseComponent implements OnInit { position: { top: '71px', right: '4.8em' }, width: "27.0rem" }); + this.inAppNotificationDialog.componentInstance.onReadAll.subscribe(() => { + this.countUnreadInappNotifications(); + }); this.inAppNotificationDialog.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { this.countUnreadInappNotifications(); this.inAppNotificationDialog = null; diff --git a/dmp-frontend/src/notification-service/ui/inapp-notification/listing-dialog/mine-inapp-notification-listing-dialog.component.ts b/dmp-frontend/src/notification-service/ui/inapp-notification/listing-dialog/mine-inapp-notification-listing-dialog.component.ts index 857adeeda..111617c5c 100644 --- a/dmp-frontend/src/notification-service/ui/inapp-notification/listing-dialog/mine-inapp-notification-listing-dialog.component.ts +++ b/dmp-frontend/src/notification-service/ui/inapp-notification/listing-dialog/mine-inapp-notification-listing-dialog.component.ts @@ -1,6 +1,6 @@ import { fromEvent, Observable, Subscription } from "rxjs"; import { HttpErrorResponse } from '@angular/common/http'; -import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; +import { Component, EventEmitter, Inject, OnDestroy, OnInit } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { Router } from '@angular/router'; import { AuthService } from '@app/core/services/auth/auth.service'; @@ -26,10 +26,11 @@ export class MineInAppNotificationListingDialogComponent extends BaseComponent i resizeObservable: Observable; resizeSubscription: Subscription; + onReadAll = new EventEmitter(); constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public dialogData: any, + @Inject(MAT_DIALOG_DATA) public data: any, private inappNotificationService: InAppNotificationService, private router: Router, private uiNotificationService: UiNotificationService, @@ -40,32 +41,15 @@ export class MineInAppNotificationListingDialogComponent extends BaseComponent i } ngOnInit() { - const lookup = new InAppNotificationLookup(); - lookup.project = { - fields: [ - nameof(x => x.id), - nameof(x => x.subject), - nameof(x => x.createdAt), - nameof(x => x.trackingState), - ] - }; - lookup.page = { offset: 0, size: 5 }; - lookup.order = { items: ['-' + nameof(x => x.createdAt)] }; - lookup.isActive = [IsActive.Active]; - this.inappNotificationService.query(lookup) - .pipe(takeUntil(this._destroyed)) - .subscribe( - data => { - this.inappNotifications = data.items; - }, - error => this.onCallbackError(error), - ); + + const lookup: InAppNotificationLookup = this.getLookup(); + this.fetchNotifications(lookup); - this.resizeObservable = fromEvent(window, 'resize'); - this.resizeSubscription = this.resizeObservable - .subscribe(evt =>{ - this.dialogRef.close(); - }); + this.resizeObservable = fromEvent(window, 'resize'); + this.resizeSubscription = this.resizeObservable + .subscribe(evt =>{ + this.dialogRef.close(); + }); } @@ -107,7 +91,40 @@ export class MineInAppNotificationListingDialogComponent extends BaseComponent i this.inappNotificationService.readAll() .pipe(takeUntil(this._destroyed)) .subscribe( - data => {}, + readAllStatus => { + if (readAllStatus) { + const lookup: InAppNotificationLookup = this.getLookup(); + this.fetchNotifications(lookup); + this.onReadAll.emit(); + } + }, ); } + + private getLookup(): InAppNotificationLookup { + const lookup = new InAppNotificationLookup(); + lookup.project = { + fields: [ + nameof(x => x.id), + nameof(x => x.subject), + nameof(x => x.createdAt), + nameof(x => x.trackingState), + ] + }; + lookup.page = { offset: 0, size: 5 }; + lookup.order = { items: ['-' + nameof(x => x.createdAt)] }; + lookup.isActive = [IsActive.Active]; + return lookup; + } + + private fetchNotifications(lookup: InAppNotificationLookup): void { + this.inappNotificationService.query(lookup) + .pipe(takeUntil(this._destroyed)) + .subscribe( + data => { + this.inappNotifications = data.items; + }, + error => this.onCallbackError(error), + ); + } }