File tree 2 files changed +49
-51
lines changed
2 files changed +49
-51
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import CONST from '../CONST' ;
3
+
4
+ type GrowlRef = {
5
+ show ?: ( bodyText : string , type : string , duration : number ) => void ;
6
+ } ;
7
+
8
+ const growlRef = React . createRef < GrowlRef > ( ) ;
9
+ let resolveIsReadyPromise : undefined | ( ( value ?: unknown ) => void ) ;
10
+ const isReadyPromise = new Promise ( ( resolve ) => {
11
+ resolveIsReadyPromise = resolve ;
12
+ } ) ;
13
+
14
+ function setIsReady ( ) {
15
+ if ( ! resolveIsReadyPromise ) return ;
16
+ resolveIsReadyPromise ( ) ;
17
+ }
18
+
19
+ /**
20
+ * Show the growl notification
21
+ */
22
+ function show ( bodyText : string , type : string , duration : number = CONST . GROWL . DURATION ) {
23
+ isReadyPromise . then ( ( ) => {
24
+ if ( ! growlRef ?. current ?. show ) return ;
25
+ growlRef . current . show ( bodyText , type , duration ) ;
26
+ } ) ;
27
+ }
28
+
29
+ /**
30
+ * Show error growl
31
+ */
32
+ function error ( bodyText : string , duration : number = CONST . GROWL . DURATION ) {
33
+ show ( bodyText , CONST . GROWL . ERROR , duration ) ;
34
+ }
35
+
36
+ /**
37
+ * Show success growl
38
+ */
39
+ function success ( bodyText : string , duration : number = CONST . GROWL . DURATION ) {
40
+ show ( bodyText , CONST . GROWL . SUCCESS , duration ) ;
41
+ }
42
+
43
+ export default {
44
+ show,
45
+ error,
46
+ success,
47
+ } ;
48
+
49
+ export { growlRef , setIsReady } ;
You can’t perform that action at this time.
0 commit comments