New notification settings

This commit is contained in:
2018-03-15 21:08:30 +01:00
parent 90021ef2f6
commit e0e8ed7996
6 changed files with 108 additions and 10 deletions

View File

@ -2,14 +2,18 @@ import { AnimeNotifier } from "../AnimeNotifier"
// Enable notifications
export async function enableNotifications(arn: AnimeNotifier, button: HTMLElement) {
arn.statusMessage.showInfo("Enabling push notifications...")
await arn.pushManager.subscribe(arn.user.dataset.id)
arn.updatePushUI()
arn.statusMessage.showInfo("Enabled push notifications for this device.")
}
// Disable notifications
export async function disableNotifications(arn: AnimeNotifier, button: HTMLElement) {
arn.statusMessage.showInfo("Disabling push notifications...")
await arn.pushManager.unsubscribe(arn.user.dataset.id)
arn.updatePushUI()
arn.statusMessage.showInfo("Disabled push notifications for this device.")
}
// Test notification

View File

@ -48,6 +48,52 @@ export function save(arn: AnimeNotifier, input: HTMLElement) {
})
}
// Enable (bool field)
export async function enable(arn: AnimeNotifier, button: HTMLButtonElement) {
let obj = {}
let apiEndpoint = arn.findAPIEndpoint(button)
obj[button.dataset.field] = true
button.disabled = true
try {
// Update boolean value
await arn.post(apiEndpoint, obj)
// Reload content
arn.reloadContent()
arn.statusMessage.showInfo("Enabled: " + button.title)
} catch(err) {
arn.statusMessage.showError(err)
} finally {
button.disabled = false
}
}
// Disable (bool field)
export async function disable(arn: AnimeNotifier, button: HTMLButtonElement) {
let obj = {}
let apiEndpoint = arn.findAPIEndpoint(button)
obj[button.dataset.field] = false
button.disabled = true
try {
// Update boolean value
await arn.post(apiEndpoint, obj)
// Reload content
arn.reloadContent()
arn.statusMessage.showInfo("Disabled: " + button.title)
} catch(err) {
arn.statusMessage.showError(err)
} finally {
button.disabled = false
}
}
// Append new element to array
export function arrayAppend(arn: AnimeNotifier, element: HTMLElement) {
let field = element.dataset.field