File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed
Expand file tree Collapse file tree 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'
24
35const SubscribeButton : React . FC = ( ) => {
6+ const [ loading , setLoading ] = useState ( false )
7+
48 const subscribe = async ( ) => {
9+ setLoading ( true )
510 try {
611 const registration = await navigator . serviceWorker . ready
712 const subscription = await registration . pushManager . subscribe ( {
@@ -25,12 +30,28 @@ const SubscribeButton: React.FC = () => {
2530 alert ( 'Subscribed to notifications' )
2631 } catch ( error ) {
2732 console . error ( 'Subscription error' , error )
33+ } finally {
34+ setLoading ( false )
2835 }
2936 }
3037
3138 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+ ) }
3455 </ button >
3556 )
3657}
You can’t perform that action at this time.
0 commit comments