Fix push notification settings not appearing when not subscribed

This commit is contained in:
Karina Kwiatek 2022-12-22 22:48:03 +00:00
parent 2f8126d732
commit dc80c1dba3
1 changed files with 10 additions and 7 deletions

View File

@ -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([