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' }, position: { top: '71px', right: '4.8em' },
width: "27.0rem" width: "27.0rem"
}); });
this.inAppNotificationDialog.componentInstance.onReadAll.subscribe(() => {
this.countUnreadInappNotifications();
});
this.inAppNotificationDialog.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { this.inAppNotificationDialog.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
this.countUnreadInappNotifications(); this.countUnreadInappNotifications();
this.inAppNotificationDialog = null; this.inAppNotificationDialog = null;

View File

@ -1,6 +1,6 @@
import { fromEvent, Observable, Subscription } from "rxjs"; import { fromEvent, Observable, Subscription } from "rxjs";
import { HttpErrorResponse } from '@angular/common/http'; 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 { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { AuthService } from '@app/core/services/auth/auth.service'; import { AuthService } from '@app/core/services/auth/auth.service';
@ -26,10 +26,11 @@ export class MineInAppNotificationListingDialogComponent extends BaseComponent i
resizeObservable: Observable<Event>; resizeObservable: Observable<Event>;
resizeSubscription: Subscription; resizeSubscription: Subscription;
onReadAll = new EventEmitter();
constructor( constructor(
public dialogRef: MatDialogRef<MineInAppNotificationListingDialogComponent>, public dialogRef: MatDialogRef<MineInAppNotificationListingDialogComponent>,
@Inject(MAT_DIALOG_DATA) public dialogData: any, @Inject(MAT_DIALOG_DATA) public data: any,
private inappNotificationService: InAppNotificationService, private inappNotificationService: InAppNotificationService,
private router: Router, private router: Router,
private uiNotificationService: UiNotificationService, private uiNotificationService: UiNotificationService,
@ -40,32 +41,15 @@ export class MineInAppNotificationListingDialogComponent extends BaseComponent i
} }
ngOnInit() { 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'); const lookup: InAppNotificationLookup = this.getLookup();
this.resizeSubscription = this.resizeObservable this.fetchNotifications(lookup);
.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() this.inappNotificationService.readAll()
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe( .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),
);
}
} }