diff --git a/mixins/Input.pixy b/mixins/Input.pixy index 15b9a588..b4fdde47 100644 --- a/mixins/Input.pixy +++ b/mixins/Input.pixy @@ -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 + ":" diff --git a/pages/settings/settings.pixy b/pages/settings/settings.pixy index 6d4500c5..9390eb50 100644 --- a/pages/settings/settings.pixy +++ b/pages/settings/settings.pixy @@ -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 diff --git a/patches/reset-notification-settings/reset-notification-settings.go b/patches/reset-notification-settings/reset-notification-settings.go new file mode 100644 index 00000000..b9679445 --- /dev/null +++ b/patches/reset-notification-settings/reset-notification-settings.go @@ -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() + } +} diff --git a/scripts/Actions/Notifications.ts b/scripts/Actions/Notifications.ts index 4aaca2c0..68b7c084 100644 --- a/scripts/Actions/Notifications.ts +++ b/scripts/Actions/Notifications.ts @@ -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 diff --git a/scripts/Actions/Serialization.ts b/scripts/Actions/Serialization.ts index f477c14a..847f3978 100644 --- a/scripts/Actions/Serialization.ts +++ b/scripts/Actions/Serialization.ts @@ -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 diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 035b02cc..5bf2a8dc 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -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") } }