Skip to content

Commit fca8f85

Browse files
Added icon + loading indicator & text + disabled loading btn state.
1 parent 8c66daa commit fca8f85

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/components/jobs/SubscribeButton.tsx

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
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

35
const 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
}

0 commit comments

Comments
 (0)