diff --git a/Frontend/src/app/services/notifications.service.ts b/Frontend/src/app/services/notifications.service.ts index b893880..0c1a566 100644 --- a/Frontend/src/app/services/notifications.service.ts +++ b/Frontend/src/app/services/notifications.service.ts @@ -15,7 +15,7 @@ export class NotificationsService { constructor( private bottomSheet$: MatBottomSheet ) { } - public add(message: Message) { + public add(message: Message): string { message.id = uuidv4(); message.createdAt = moment(); this.messages.push(message); @@ -27,11 +27,16 @@ export class NotificationsService { }); } setTimeout(() => { - this.remove(message); + this.remove(message.id); }, message.duration ? message.duration : 5000); + // close parent + if (message.parentId) { + this.remove(message.parentId); + } + return message.id; } - private remove(message: Message) { - this.messages = this.messages.filter(x => x.id!==message.id); + private remove(id: string|undefined) { + this.messages = this.messages.filter(x => x.id!==id); this.sortMessages(); if (this.messages.length === 0 && this.handler) { this.handler.dismiss(); @@ -44,7 +49,7 @@ export class NotificationsService { } doAction(message: Message) { if (message.action) { message.action(); } - this.remove(message); + this.remove(message.id); } } @@ -55,5 +60,6 @@ interface Message { btn?: string; // eslint-disable-next-line @typescript-eslint/ban-types action?: Function; - createdAt?: Moment + createdAt?: Moment, + parentId?: string; }