File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
app/component/itinerary/navigator/hooks Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { useState , useEffect } from 'react' ;
2
2
3
+ navigator . serviceWorker . register ( '/sw.js' ) ;
4
+
3
5
const usePushNotification = config => {
4
6
const [ notification , setNotification ] = useState ( null ) ;
5
7
@@ -14,10 +16,12 @@ const usePushNotification = config => {
14
16
15
17
const createNotification = ( title , content ) => {
16
18
if ( 'Notification' in window && Notification . permission === 'granted' ) {
17
- const newNotification = new Notification ( title , {
18
- body : content ,
19
+ navigator . serviceWorker . ready . then ( registration => {
20
+ const newNotification = registration . showNotification ( title , {
21
+ body : content ,
22
+ } ) ;
23
+ setNotification ( newNotification ) ;
19
24
} ) ;
20
- setNotification ( newNotification ) ;
21
25
}
22
26
} ;
23
27
const notificationConsent = ( ) => {
You can’t perform that action at this time.
0 commit comments