Skip to content

Commit 0aab68a

Browse files
authored
Merge pull request #5413 from HSLdevcom/DT-6178-next-test
test push notifications
2 parents db8f3bf + 650c1c2 commit 0aab68a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

app/component/itinerary/navigator/hooks/usePushNotification.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useState, useEffect } from 'react';
22

3+
navigator.serviceWorker.register('/sw.js');
4+
35
const usePushNotification = config => {
46
const [notification, setNotification] = useState(null);
57

@@ -14,10 +16,12 @@ const usePushNotification = config => {
1416

1517
const createNotification = (title, content) => {
1618
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);
1924
});
20-
setNotification(newNotification);
2125
}
2226
};
2327
const notificationConsent = () => {

0 commit comments

Comments
 (0)