add button loading state
This commit is contained in:
@@ -59,6 +59,9 @@ async function onButtonClick() {
|
|||||||
}
|
}
|
||||||
getSummaryButton.innerText = "Get daily updates at 7am"
|
getSummaryButton.innerText = "Get daily updates at 7am"
|
||||||
} else {
|
} else {
|
||||||
|
getSummaryButton.innerText = "Subscribing"
|
||||||
|
getSummaryButton.disabled = true
|
||||||
|
|
||||||
const worker = await navigator.serviceWorker.ready
|
const worker = await navigator.serviceWorker.ready
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -75,7 +78,6 @@ async function onButtonClick() {
|
|||||||
|
|
||||||
let newSubscription
|
let newSubscription
|
||||||
if (registeredSubscription) {
|
if (registeredSubscription) {
|
||||||
registeredSubscription.locations.push(loc)
|
|
||||||
newSubscription = await fetch(`/registrations/${registeredSubscription.id}`, {
|
newSubscription = await fetch(`/registrations/${registeredSubscription.id}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -83,7 +85,7 @@ async function onButtonClick() {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
subscription: pushSub,
|
subscription: pushSub,
|
||||||
locations: registeredSubscription.locations,
|
locations: [loc],
|
||||||
})
|
})
|
||||||
}).then(jsonOrThrow)
|
}).then(jsonOrThrow)
|
||||||
} else {
|
} else {
|
||||||
@@ -105,6 +107,9 @@ async function onButtonClick() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
alert(`Error when trying to subscribe to updates: ${error}`)
|
alert(`Error when trying to subscribe to updates: ${error}`)
|
||||||
|
getSummaryButton.innerText = "Get daily updates at 7am"
|
||||||
|
} finally {
|
||||||
|
getSummaryButton.disabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user