From 7fd48d8155b20deb077812826c7a361e5295e8ac Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Fri, 2 Aug 2019 15:53:31 +0300 Subject: [PATCH] Fix enabling and disabling push notifications. --- client/components/Windows/Settings.vue | 11 ++++++++++- client/js/webpush.js | 13 ++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/client/components/Windows/Settings.vue b/client/components/Windows/Settings.vue index b8a0283b..ed33cc3e 100644 --- a/client/components/Windows/Settings.vue +++ b/client/components/Windows/Settings.vue @@ -264,8 +264,9 @@ id="pushNotifications" type="button" class="btn" - disabled + :disabled="$root.pushNotificationState !== 'supported'" data-text-alternate="Unsubscribe from push notifications" + @click="onPushButtonClick" >Subscribe to push notifications
diff --git a/client/js/webpush.js b/client/js/webpush.js index 4e757cf1..5b55b8aa 100644 --- a/client/js/webpush.js +++ b/client/js/webpush.js @@ -67,13 +67,16 @@ module.exports.initialize = () => { alternatePushButton(); } }); - }).catch(() => { - vueApp.pushNotificationState = "unsupported"; - }); + }) + .catch(() => { + vueApp.pushNotificationState = "unsupported"; + }); } }; -function onPushButton() { +module.exports.onPushButton = () => { + // TODO: move dom logic to Settings.vue + pushNotificationsButton = $("#pushNotifications"); pushNotificationsButton.prop("disabled", true); navigator.serviceWorker.ready @@ -127,7 +130,7 @@ function onPushButton() { }); return false; -} +}; function alternatePushButton() { const text = pushNotificationsButton.text();