Skip to content
This repository has been archived by the owner on Apr 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #125 from SAKPaaS/bugfix/58-snackbar-again
Browse files Browse the repository at this point in the history
Fixed Snack-Bar Bug (hopefully)
  • Loading branch information
timgrohmann authored Apr 9, 2020
2 parents 4d686dd + 68c33a0 commit a441098
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 10 additions & 4 deletions SAKPaaS/src/app/components/snack-bar/snack-bar.component.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -16,7 +15,7 @@ export class SnackBarComponent implements OnInit {

private isSnackBarLoading = false;

private notificationQueue: ISnackBar[] = [];
private notificationQueue: ISnackBarInternal[] = [];

constructor(
private snackBarService: SnackBarService,
Expand All @@ -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);
Expand Down Expand Up @@ -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(() => {
Expand Down
6 changes: 5 additions & 1 deletion SAKPaaS/src/app/core/models/snack-bar.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ export enum SnackBarTypes {

export interface ISnackBar {
messageKey: string;
valuesForMessage?: {[key: string]: string};
valuesForMessage?: { [key: string]: string };
type: SnackBarTypes;
closeObservable?: Observable<null>;
big?: boolean;
hideCloseButton?: boolean;
}

export interface ISnackBarInternal extends ISnackBar {
closed?: boolean;
}

0 comments on commit a441098

Please sign in to comment.