1
1
import { htmlEscape } from 'escape-goat' ;
2
2
import { 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
4
4
5
5
const levels = {
6
6
info : {
@@ -21,9 +21,7 @@ const levels = {
21
21
} ;
22
22
23
23
// 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 } = { } ) {
27
25
const { icon, background, duration : levelDuration } = levels [ level ?? 'info' ] ;
28
26
29
27
const toast = Toastify ( {
@@ -41,20 +39,17 @@ async function showToast(message, level, {gravity, position, duration, ...other}
41
39
} ) ;
42
40
43
41
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 ( ) ) ;
48
43
}
49
44
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 ) ;
52
47
}
53
48
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 ) ;
56
51
}
57
52
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 ) ;
60
55
}
0 commit comments