1
0
mirror of https://github.com/bitwarden/web synced 2025-12-06 00:03:28 +00:00

Replace toaster library (#1322)

This commit is contained in:
Oscar Hinton
2021-12-07 19:41:45 +00:00
committed by GitHub
parent 35a7d6434a
commit d5c0783619
87 changed files with 336 additions and 508 deletions

View File

@@ -1,13 +1,3 @@
import * as jq from 'jquery';
import Swal from 'sweetalert2';
import {
BodyOutputType,
Toast,
ToasterConfig,
ToasterService,
} from 'angular2-toaster';
import {
Component,
NgZone,
@@ -20,6 +10,9 @@ import {
NavigationEnd,
Router,
} from '@angular/router';
import * as jq from 'jquery';
import { IndividualConfig, ToastrService } from 'ngx-toastr';
import Swal from 'sweetalert2';
import { AuthService } from 'jslib-common/abstractions/auth.service';
import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service';
@@ -67,13 +60,6 @@ const IdleTimeout = 60000 * 10; // 10 minutes
})
export class AppComponent implements OnDestroy, OnInit {
toasterConfig: ToasterConfig = new ToasterConfig({
showCloseButton: true,
mouseoverTimerStop: true,
animation: 'flyRight',
limit: 5,
});
private lastActivity: number = null;
private idleTimer: number = null;
private isIdle = false;
@@ -84,7 +70,7 @@ export class AppComponent implements OnDestroy, OnInit {
private settingsService: SettingsService, private syncService: SyncService,
private passwordGenerationService: PasswordGenerationService, private cipherService: CipherService,
private authService: AuthService, private router: Router,
private toasterService: ToasterService, private i18nService: I18nService,
private toastrService: ToastrService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private ngZone: NgZone,
private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService,
private cryptoService: CryptoService, private collectionService: CollectionService,
@@ -228,7 +214,7 @@ export class AppComponent implements OnDestroy, OnInit {
this.searchService.clearIndex();
this.authService.logOut(async () => {
if (expired) {
this.toasterService.popAsync('warning', this.i18nService.t('loggedOut'),
this.platformUtilsService.showToast('warning', this.i18nService.t('loggedOut'),
this.i18nService.t('loginExpired'));
}
@@ -264,30 +250,29 @@ export class AppComponent implements OnDestroy, OnInit {
}
private showToast(msg: any) {
const toast: Toast = {
type: msg.type,
title: msg.title,
};
let message = '';
const options: Partial<IndividualConfig> = {};
if (typeof (msg.text) === 'string') {
toast.body = msg.text;
message = msg.text;
} else if (msg.text.length === 1) {
toast.body = msg.text[0];
message = msg.text[0];
} else {
let message = '';
msg.text.forEach((t: string) =>
message += ('<p>' + this.sanitizer.sanitize(SecurityContext.HTML, t) + '</p>'));
toast.body = message;
toast.bodyOutputType = BodyOutputType.TrustedHtml;
options.enableHtml = true;
}
if (msg.options != null) {
if (msg.options.trustedHtml === true) {
toast.bodyOutputType = BodyOutputType.TrustedHtml;
options.enableHtml = true;
}
if (msg.options.timeout != null && msg.options.timeout > 0) {
toast.timeout = msg.options.timeout;
options.timeOut = msg.options.timeout;
}
}
this.toasterService.popAsync(toast);
this.toastrService.show(message, msg.title, options, 'toast-' + msg.type);
}
private idleStateChanged() {