Notifications: parentId

This commit is contained in:
2023-01-12 15:32:03 +01:00
parent 2bd858501d
commit ee2f371b21

View File

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