From dc80c1dba38add19ab8250aa0c87947cf06a3dc6 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Thu, 22 Dec 2022 22:48:03 +0000 Subject: [PATCH] Fix push notification settings not appearing when not subscribed --- .../retrospring/features/webpush/index.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/javascript/retrospring/features/webpush/index.ts b/app/javascript/retrospring/features/webpush/index.ts index dcdbeef1..681284fb 100644 --- a/app/javascript/retrospring/features/webpush/index.ts +++ b/app/javascript/retrospring/features/webpush/index.ts @@ -8,19 +8,22 @@ export default (): void => { const notificationCapable = document.body.classList.contains('cap-notification'); if (swCapable && notificationCapable) { + const enableBtn = document.querySelector('button[data-action="push-enable"]'); - navigator.serviceWorker.getRegistration().then(registration => { - return registration.pushManager.getSubscription().then(subscription => { - if (!subscription) { - document.querySelector('button[data-action="push-enable"]').classList.remove('d-none'); - } else { + if (!enableBtn) return; + + enableBtn.classList.remove('d-none'); + + navigator.serviceWorker.getRegistration().then(registration => + registration?.pushManager.getSubscription().then(subscription => { + if (subscription) { + document.querySelector('button[data-action="push-enable"]').classList.add('d-none'); document.querySelector('[data-action="push-disable"]').classList.remove('d-none'); if (localStorage.getItem('dismiss-push-settings-prompt') == null) { document.querySelector('.push-settings')?.classList.remove('d-none'); } } - }); - }); + })); } registerEvents([