Commit 85748665d3250e6a60613c461640ce39287055b0

Authored by Igor Kulikov
1 parent 8f4944fe

Toast improvements

... ... @@ -47,6 +47,8 @@ export class ToastDirective implements AfterViewInit, OnDestroy {
47 47 private notificationSubscription: Subscription = null;
48 48 private hideNotificationSubscription: Subscription = null;
49 49
  50 + private snackBarRef: MatSnackBarRef<TbSnackBarComponent> = null;
  51 +
50 52 constructor(public elementRef: ElementRef,
51 53 public viewContainerRef: ViewContainerRef,
52 54 private notificationService: NotificationService,
... ... @@ -55,8 +57,6 @@ export class ToastDirective implements AfterViewInit, OnDestroy {
55 57 }
56 58
57 59 ngAfterViewInit(): void {
58   - const toastComponent = this;
59   -
60 60 this.notificationSubscription = this.notificationService.getNotification().subscribe(
61 61 (notificationMessage) => {
62 62 if (notificationMessage && notificationMessage.message) {
... ... @@ -70,11 +70,17 @@ export class ToastDirective implements AfterViewInit, OnDestroy {
70 70 const config: MatSnackBarConfig = {
71 71 horizontalPosition: notificationMessage.horizontalPosition || 'left',
72 72 verticalPosition: !isGtSm ? 'bottom' : (notificationMessage.verticalPosition || 'top'),
73   - viewContainerRef: toastComponent.viewContainerRef,
  73 + viewContainerRef: this.viewContainerRef,
74 74 duration: notificationMessage.duration,
75 75 data
76 76 };
77   - this.snackBar.openFromComponent(TbSnackBarComponent, config);
  77 + if (this.snackBarRef) {
  78 + this.snackBarRef.dismiss();
  79 + }
  80 + this.snackBarRef = this.snackBar.openFromComponent(TbSnackBarComponent, config);
  81 + this.snackBarRef.afterDismissed().subscribe(() => {
  82 + this.snackBarRef = null;
  83 + });
78 84 }
79 85 }
80 86 }
... ...