update toaster service
This commit is contained in:
parent
a4e425d373
commit
eb58e96d01
@ -4,9 +4,9 @@ import { IndividualConfig } from 'ngx-toastr/toastr/toastr-config';
|
||||
import { NavigationStart, Router } from '@angular/router';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { filter, tap } from 'rxjs/operators';
|
||||
import { ErrorMessageService } from './error-message.service';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
|
||||
const enum NotificationType {
|
||||
SUCCESS = 'SUCCESS',
|
||||
@ -40,15 +40,18 @@ export interface ErrorToasterOptions extends ToasterOptions {
|
||||
})
|
||||
export class Toaster {
|
||||
constructor(
|
||||
router: Router,
|
||||
private readonly _toastr: ToastrService,
|
||||
private readonly _router: Router,
|
||||
private readonly _translateService: TranslateService,
|
||||
private readonly _errorMessageService: ErrorMessageService,
|
||||
private readonly _sanitizer: DomSanitizer,
|
||||
) {
|
||||
_router.events.pipe(filter(event => event instanceof NavigationStart)).subscribe(() => {
|
||||
_toastr.clear();
|
||||
});
|
||||
router.events
|
||||
.pipe(
|
||||
filter(event => event instanceof NavigationStart),
|
||||
tap(() => _toastr.clear()),
|
||||
takeUntilDestroyed(),
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
error(message: string, options?: Partial<ErrorToasterOptions>): ActiveToast<unknown> {
|
||||
@ -63,18 +66,18 @@ export class Toaster {
|
||||
}
|
||||
|
||||
info(message: string, options?: Partial<ToasterOptions>): ActiveToast<unknown> {
|
||||
return this._showToastNotification(message, NotificationType.INFO, options);
|
||||
return this.#showToastNotification(message, NotificationType.INFO, options);
|
||||
}
|
||||
|
||||
success(message: string, options?: Partial<ToasterOptions>): ActiveToast<unknown> {
|
||||
return this._showToastNotification(message, NotificationType.SUCCESS, options);
|
||||
return this.#showToastNotification(message, NotificationType.SUCCESS, options);
|
||||
}
|
||||
|
||||
warning(message: string, options?: Partial<ToasterOptions>): ActiveToast<unknown> {
|
||||
return this._showToastNotification(message, NotificationType.WARNING, options);
|
||||
return this.#showToastNotification(message, NotificationType.WARNING, options);
|
||||
}
|
||||
|
||||
private _showToastNotification(
|
||||
#showToastNotification(
|
||||
message: string,
|
||||
notificationType = NotificationType.INFO,
|
||||
options?: Partial<ToasterOptions>,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user