New notification settings

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

View File

@ -3,6 +3,19 @@ component InputText(id string, value string, label string, placeholder string)
label(for=id)= label + ":"
input.widget-ui-element.action(id=id, data-field=id, type="text", value=value, placeholder=placeholder, title=placeholder, data-action="save", data-trigger="change")
component InputBool(id string, value bool, label string, title string)
.widget-section
label(for=id)= label + ":"
if value
button.action(id=id, data-action="disable", data-trigger="click", data-field=id, title=title)
Icon("toggle-on")
span ON
else
button.action(id=id, data-action="enable", data-trigger="click", data-field=id, title=title)
Icon("toggle-off")
span OFF
//- input.widget-ui-element.action(id=id, data-field=id, type="checkbox", value=value, checked=value, data-action="save", data-trigger="change")
component InputTextArea(id string, value string, label string, placeholder string)
.widget-section
label(for=id)= label + ":"

View File

@ -89,25 +89,47 @@ component SettingsNotifications(user *arn.User)
.widget.mountable
h3.widget-title
Icon("bell")
span Notifications
span Push notifications
#enable-notifications.widget-section
label Enable:
button.action(data-action="enableNotifications", data-trigger="click")
Icon("toggle-off")
span Enable notifications
span Enable push notifications
#disable-notifications.widget-section
#disable-notifications.widget-section.hidden
label Disable:
button.action(data-action="disableNotifications", data-trigger="click")
Icon("toggle-on")
span Disable notifications
span Disable push notifications
#test-notification.widget-section
label Test:
button.action(data-action="testNotification", data-trigger="click")
Icon("paper-plane")
span Send test notification
.footer
p(title="This setting is not account bound, instead it is bound to your browser.") You can customize this setting on every device you own.
.widget.mountable(data-api="/api/settings/" + user.ID)
h3.widget-title
Icon("filter")
span General
InputBool("Notification.AnimeEpisodeReleases", user.Settings().Notification.AnimeEpisodeReleases, "New episodes", "Notifications about new episodes")
InputBool("Notification.AnimeFinished", user.Settings().Notification.AnimeFinished, "Finished anime series", "Notifications about finished anime series")
InputBool("Notification.NewFollowers", user.Settings().Notification.NewFollowers, "New followers", "Notifications about new followers")
.widget.mountable(data-api="/api/settings/" + user.ID)
h3.widget-title
Icon("heart")
span Likes
InputBool("Notification.ForumLikes", user.Settings().Notification.ForumLikes, "Forum post likes", "Notifications about forum post likes")
InputBool("Notification.SoundTrackLikes", user.Settings().Notification.SoundTrackLikes, "Soundtrack likes", "Notifications about soundtrack likes")
//- InputBool("Notification.GroupPostLikes", user.Settings().Notification.GroupPostLikes, "Group post likes", "Notifications about group post likes")
InputBool("Notification.QuoteLikes", user.Settings().Notification.QuoteLikes, "Quote likes", "Notifications about quote likes")
component SettingsApps(user *arn.User)
SettingsTabs

View File

@ -0,0 +1,13 @@
package main
import "github.com/animenotifier/arn"
func main() {
defer arn.Node.Close()
for user := range arn.StreamUsers() {
settings := user.Settings()
settings.Notification = arn.DefaultNotificationSettings()
settings.Save()
}
}

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

View File

@ -312,8 +312,8 @@ export class AnimeNotifier {
let testButton = this.app.find("test-notification") as HTMLButtonElement
if(!this.pushManager.pushSupported) {
enableButton.style.display = "none"
disableButton.style.display = "none"
enableButton.classList.add("hidden")
disableButton.classList.add("hidden")
testButton.innerHTML = "Your browser doesn't support push notifications!"
return
}
@ -321,11 +321,11 @@ export class AnimeNotifier {
let subscription = await this.pushManager.subscription()
if(subscription) {
enableButton.style.display = "none"
disableButton.style.display = "flex"
enableButton.classList.add("hidden")
disableButton.classList.remove("hidden")
} else {
enableButton.style.display = "flex"
disableButton.style.display = "none"
enableButton.classList.remove("hidden")
disableButton.classList.add("hidden")
}
}