Fix stuck state when permission granted but no subscription

When you had already granted notification permission but hadn't
completed the subscription flow (no service worker or no push
subscription), the UI showed neither the subscribe button nor the
enabled state, leaving you stuck with no way to subscribe, and wrong
instructions to fix it.

Instead, let's just show the button to allow you to subscribe.
This commit is contained in:
Rosa Gutierrez
2026-01-23 13:29:33 +01:00
committed by Rosa Gutierrez
parent 40946930d0
commit c650cba179
@@ -11,8 +11,7 @@ export default class extends Controller {
switch(Notification.permission) {
case "default":
this.subscribeButtonTarget.hidden = false
this.explainerTarget.hidden = true
this.#showButtonToSubscribe()
break
case "granted":
const registration = await this.#getServiceWorkerRegistration()
@@ -20,6 +19,8 @@ export default class extends Controller {
if (registration && subscription) {
this.element.classList.add(this.enabledClass)
} else {
this.#showButtonToSubscribe()
}
break
}
@@ -76,6 +77,11 @@ export default class extends Controller {
}
}
#showButtonToSubscribe() {
this.subscribeButtonTarget.hidden = false
this.explainerTarget.hidden = true
}
async #requestPermissionAndSubscribe(registration) {
const permission = await Notification.requestPermission()
if (permission === "granted") this.#subscribe(registration)