11import { htmlEscape } from 'escape-goat' ;
22import { svg } from '../svg.js' ;
3- import Toastify from 'toastify-js' ;
3+ import Toastify from 'toastify-js' ; // don't use "async import", because when network error occurs, the "async import" also fails and nothing is shown
44
55const levels = {
66 info : {
@@ -21,9 +21,7 @@ const levels = {
2121} ;
2222
2323// See https://github.com/apvarun/toastify-js#api for options
24- async function showToast ( message , level , { gravity, position, duration, ...other } = { } ) {
25- if ( ! message ) return ;
26-
24+ function showToast ( message , level , { gravity, position, duration, ...other } = { } ) {
2725 const { icon, background, duration : levelDuration } = levels [ level ?? 'info' ] ;
2826
2927 const toast = Toastify ( {
@@ -41,20 +39,17 @@ async function showToast(message, level, {gravity, position, duration, ...other}
4139 } ) ;
4240
4341 toast . showToast ( ) ;
44-
45- toast . toastElement . querySelector ( '.toast-close' ) . addEventListener ( 'click' , ( ) => {
46- toast . removeElement ( toast . toastElement ) ;
47- } ) ;
42+ toast . toastElement . querySelector ( '.toast-close' ) . addEventListener ( 'click' , ( ) => toast . hideToast ( ) ) ;
4843}
4944
50- export async function showInfoToast ( message , opts ) {
51- return await showToast ( message , 'info' , opts ) ;
45+ export function showInfoToast ( message , opts ) {
46+ return showToast ( message , 'info' , opts ) ;
5247}
5348
54- export async function showWarningToast ( message , opts ) {
55- return await showToast ( message , 'warning' , opts ) ;
49+ export function showWarningToast ( message , opts ) {
50+ return showToast ( message , 'warning' , opts ) ;
5651}
5752
58- export async function showErrorToast ( message , opts ) {
59- return await showToast ( message , 'error' , opts ) ;
53+ export function showErrorToast ( message , opts ) {
54+ return showToast ( message , 'error' , opts ) ;
6055}
0 commit comments