clean up dupe code + make sure failing analytics doesn't throw subscription error.

This commit is contained in:
Dan Peterson 2021-12-29 13:26:28 -06:00 committed by Thomas Zarebczan
parent c22a3048dc
commit 60430b5267

View file

@ -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 () => {