update status on in-app-notificatons-dialog "read all"

This commit is contained in:
Sofia Papacharalampous 2024-05-20 11:37:42 +03:00
parent 211e2044dd
commit 05a90d6fbd
2 changed files with 48 additions and 28 deletions

View File

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

View File

@ -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<Event>;
resizeSubscription: Subscription;
onReadAll = new EventEmitter();
constructor(
public dialogRef: MatDialogRef<MineInAppNotificationListingDialogComponent>,
@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<InAppNotification>(x => x.id),
nameof<InAppNotification>(x => x.subject),
nameof<InAppNotification>(x => x.createdAt),
nameof<InAppNotification>(x => x.trackingState),
]
};
lookup.page = { offset: 0, size: 5 };
lookup.order = { items: ['-' + nameof<InAppNotification>(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),
);
this.resizeObservable = fromEvent(window, 'resize');
this.resizeSubscription = this.resizeObservable
.subscribe(evt =>{
this.dialogRef.close();
});
const lookup: InAppNotificationLookup = this.getLookup();
this.fetchNotifications(lookup);
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<InAppNotification>(x => x.id),
nameof<InAppNotification>(x => x.subject),
nameof<InAppNotification>(x => x.createdAt),
nameof<InAppNotification>(x => x.trackingState),
]
};
lookup.page = { offset: 0, size: 5 };
lookup.order = { items: ['-' + nameof<InAppNotification>(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),
);
}
}