clean up dupe code + make sure failing analytics doesn't throw subscription error.
This commit is contained in:
parent
c22a3048dc
commit
60430b5267
1 changed files with 3 additions and 6 deletions
|
@ -35,19 +35,16 @@ export default () => {
|
|||
if (!user) return;
|
||||
setEncounteredError(false);
|
||||
try {
|
||||
if (await pushNotifications.subscribe(user.id)) {
|
||||
const subscribed = await pushNotifications.subscribe(user.id);
|
||||
if (subscribed) {
|
||||
setSubscribed(true);
|
||||
setPushPermission(window.Notification?.permission);
|
||||
analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribed' });
|
||||
return true;
|
||||
} else {
|
||||
setEncounteredError(true);
|
||||
analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribe_failed' });
|
||||
}
|
||||
} catch {
|
||||
setEncounteredError(true);
|
||||
analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribe_failed' });
|
||||
}
|
||||
analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'subscribed' });
|
||||
};
|
||||
|
||||
const unsubscribe = async () => {
|
||||
|
|
Loading…
Reference in a new issue