From ee2f371b21d60f893cdabd035ad5ee36af851f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Thu, 12 Jan 2023 15:32:03 +0100 Subject: [PATCH] Notifications: parentId --- .../src/app/services/notifications.service.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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; }