Skip to content

Commit

Permalink
Clean up push controller js even more (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
melroy89 authored Sep 11, 2024
1 parent 3498eb3 commit ac20a32
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions assets/controllers/push_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default class extends Controller {
this.askPermission()
.then(() => window.navigator.serviceWorker.getRegistration())
.then(registration => {
console.log("got service worker registration:", registration)
const subscribeOptions = {
userVisibleOnly: true,
applicationServerKey: this.applicationServerPublicKey,
Expand All @@ -83,10 +82,8 @@ export default class extends Controller {
return registration.pushManager.subscribe(subscribeOptions)
})
.then(pushSubscription => {
console.log("Received PushSubscription: ", JSON.stringify(pushSubscription))
this.updateButtonVisibility(pushSubscription)
const jsonSub = pushSubscription.toJSON()
console.log("registering push to server")
let payload = {
endpoint: pushSubscription.endpoint,
deviceKey: this.getDeviceKey(),
Expand All @@ -104,9 +101,6 @@ export default class extends Controller {
throw response
}
return response.json()
})
.then(data => {

})
.catch(error => {
console.error(error)
Expand All @@ -120,7 +114,6 @@ export default class extends Controller {
.then(pushSubscription => pushSubscription.unsubscribe())
.then((successful) => {
if (successful) {
console.log("removed push subscription")
this.updateButtonVisibility(null)
let payload = {
deviceKey: this.getDeviceKey(),
Expand All @@ -135,6 +128,9 @@ export default class extends Controller {
})
.catch(error => console.error(error))
}
})
.catch((error) => {
console.error("There was an error in the service worker registration method, for unsubscribing", error)
})
}

Expand Down

0 comments on commit ac20a32

Please sign in to comment.