From 68c33a0cd47b963cd4414658570656a5eea251bf Mon Sep 17 00:00:00 2001 From: timgrohmann Date: Wed, 8 Apr 2020 17:56:30 +0200 Subject: [PATCH] fixed snackbar bug (hopefully) --- .../components/snack-bar/snack-bar.component.ts | 14 ++++++++++---- SAKPaaS/src/app/core/models/snack-bar.interface.ts | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/SAKPaaS/src/app/components/snack-bar/snack-bar.component.ts b/SAKPaaS/src/app/components/snack-bar/snack-bar.component.ts index e19b925b..121644f2 100644 --- a/SAKPaaS/src/app/components/snack-bar/snack-bar.component.ts +++ b/SAKPaaS/src/app/components/snack-bar/snack-bar.component.ts @@ -1,9 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { SnackBarService } from 'src/app/core/services/snack-bar.service'; import { MatSnackBar, MatSnackBarConfig, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar'; -import { SnackBarTypes, ISnackBar } from 'src/app/core/models/snack-bar.interface'; +import { SnackBarTypes, ISnackBarInternal } from 'src/app/core/models/snack-bar.interface'; import { TranslateService } from '@ngx-translate/core'; -import { first } from 'rxjs/operators'; @Component({ selector: 'app-snack-bar', @@ -16,7 +15,7 @@ export class SnackBarComponent implements OnInit { private isSnackBarLoading = false; - private notificationQueue: ISnackBar[] = []; + private notificationQueue: ISnackBarInternal[] = []; constructor( private snackBarService: SnackBarService, @@ -25,9 +24,13 @@ export class SnackBarComponent implements OnInit { ) { } ngOnInit(): void { - this.snackBarService.getNotification().subscribe(notification => { + this.snackBarService.getNotification().subscribe(extNotification => { + const notification = extNotification as ISnackBarInternal; this.notificationQueue.push(notification); notification.closeObservable?.subscribe(() => { + // marks the notification as closed + // this needs to be done because opening happens asynchronously + notification.closed = true; // If the observable is triggered while the notification is // still on the queue it should be removed from it const index = this.notificationQueue.indexOf(notification); @@ -58,6 +61,9 @@ export class SnackBarComponent implements OnInit { this.translate.get(nextNotification.messageKey, nextNotification.valuesForMessage).subscribe(message => { this.isSnackBarLoading = false; + // if the notification has been dismissed during the translation fix it must not be displayed + if (nextNotification.closed) { this.next(); return; } + if (nextNotification.closeObservable) { config.duration = null; nextNotification.closeObservable.subscribe(() => { diff --git a/SAKPaaS/src/app/core/models/snack-bar.interface.ts b/SAKPaaS/src/app/core/models/snack-bar.interface.ts index 213d3e2d..14b1f88d 100644 --- a/SAKPaaS/src/app/core/models/snack-bar.interface.ts +++ b/SAKPaaS/src/app/core/models/snack-bar.interface.ts @@ -8,9 +8,13 @@ export enum SnackBarTypes { export interface ISnackBar { messageKey: string; - valuesForMessage?: {[key: string]: string}; + valuesForMessage?: { [key: string]: string }; type: SnackBarTypes; closeObservable?: Observable; big?: boolean; hideCloseButton?: boolean; } + +export interface ISnackBarInternal extends ISnackBar { + closed?: boolean; +}