Skip to content

Commit 90fda98

Browse files
authored
Merge pull request #43 from notificationapi-com/WHCxBqkW/3275-react-sdk-web-push-bug
Bump version from 1.1.3 to 1.1.4 in package.json and package-lock.json; refactor NotificationAPIProvider to improve web push opt-in logic
2 parents 49ab860 + 9e49e45 commit 90fda98

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

lib/components/Provider/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -439,25 +439,28 @@ export const NotificationAPIProvider: React.FunctionComponent<
439439
}, [client, loadNotifications, askForWebPushPermission]);
440440

441441
useEffect(() => {
442-
if (
443-
isClient &&
444-
'Notification' in window &&
445-
typeof Notification.requestPermission === 'function'
446-
) {
447-
if (Notification.permission !== 'default') {
448-
setWebPushOptInMessage(false);
449-
}
450-
}
451442
client.getUserAccountMetadata().then((res) => {
452443
setUserAccountMetaData(res);
453-
setWebPushOptInMessage(res.userAccountMetadata.hasWebPushEnabled);
444+
if (
445+
isClient &&
446+
'Notification' in window &&
447+
typeof Notification.requestPermission === 'function'
448+
) {
449+
if (Notification.permission !== 'default') {
450+
setWebPushOptInMessage(false);
451+
}
452+
} else {
453+
setWebPushOptInMessage(res.userAccountMetadata.hasWebPushEnabled);
454+
}
454455
});
456+
}, [client]);
457+
useEffect(() => {
455458
if (webPushOptInMessage === 'AUTOMATIC') {
456459
setWebPushOptInMessage(
457460
localStorage.getItem('hideWebPushOptInMessage') !== 'true'
458461
);
459462
}
460-
}, [client, webPushOptInMessage]);
463+
}, [webPushOptInMessage]);
461464
useEffect(() => {
462465
if (webPushOptIn) {
463466
askForWebPushPermission();

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@notificationapi/react",
33
"private": false,
4-
"version": "1.1.3",
4+
"version": "1.1.4",
55
"type": "module",
66
"overrides": {
77
"esbuild": "^0.25.0",

0 commit comments

Comments
 (0)