File tree 1 file changed +24
-3
lines changed
1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change 1
- import React from 'react'
1
+ import React , { useState } from 'react'
2
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
3
+ import { faBell , faSpinner } from '@fortawesome/free-solid-svg-icons'
2
4
3
5
const SubscribeButton : React . FC = ( ) => {
6
+ const [ loading , setLoading ] = useState ( false )
7
+
4
8
const subscribe = async ( ) => {
9
+ setLoading ( true )
5
10
try {
6
11
const registration = await navigator . serviceWorker . ready
7
12
const subscription = await registration . pushManager . subscribe ( {
@@ -25,12 +30,28 @@ const SubscribeButton: React.FC = () => {
25
30
alert ( 'Subscribed to notifications' )
26
31
} catch ( error ) {
27
32
console . error ( 'Subscription error' , error )
33
+ } finally {
34
+ setLoading ( false )
28
35
}
29
36
}
30
37
31
38
return (
32
- < button onClick = { subscribe } className = "p-2 bg-blue-500 text-white rounded" >
33
- Subscribe
39
+ < button
40
+ onClick = { subscribe }
41
+ disabled = { loading }
42
+ className = "p-2 bg-blue-500 text-white rounded flex items-center gap-2"
43
+ >
44
+ { loading ? (
45
+ < >
46
+ < FontAwesomeIcon icon = { faSpinner } spin />
47
+ Loading...
48
+ </ >
49
+ ) : (
50
+ < >
51
+ < FontAwesomeIcon icon = { faBell } />
52
+ Subscribe
53
+ </ >
54
+ ) }
34
55
</ button >
35
56
)
36
57
}
You can’t perform that action at this time.
0 commit comments