From 241e6f7e3ae25517e14d5ef993537f6748c70d0e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 8 Apr 2024 22:18:42 -0400 Subject: [PATCH] Notification type toggles --- .../Notifications/PushSubscriptionView.swift | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Tusker/Screens/Preferences/Notifications/PushSubscriptionView.swift b/Tusker/Screens/Preferences/Notifications/PushSubscriptionView.swift index 3d4d6e3d..86b49073 100644 --- a/Tusker/Screens/Preferences/Notifications/PushSubscriptionView.swift +++ b/Tusker/Screens/Preferences/Notifications/PushSubscriptionView.swift @@ -40,9 +40,14 @@ private struct PushSubscriptionSettingsView: View { var body: some View { VStack(alignment: .prefsAvatar) { - AsyncToggle("Mentions", mode: alertsBinding(for: .mention)) { - await onChange(alert: .mention, value: $0) - } + toggle("All", alert: [.mention, .favorite, .reblog, .follow, .followRequest, .poll, .update]) + toggle("Mentions", alert: .mention) + toggle("Favorites", alert: .favorite) + toggle("Reblogs", alert: .reblog) + toggle("Follows", alert: [.follow, .followRequest]) + toggle("Polls", alert: .poll) + toggle("Edits", alert: .update) + // status notifications not supported until we can enable/disable them in the app } // this is the default value of the alignment guide, but this modifier is loading bearing .alignmentGuide(.prefsAvatar, computeValue: { dimension in @@ -52,17 +57,20 @@ private struct PushSubscriptionSettingsView: View { .padding(.leading, 38) } - private func alertsBinding(for alert: PushSubscription.Alerts) -> Binding { - return Binding { + private func toggle(_ titleKey: LocalizedStringKey, alert: PushSubscription.Alerts) -> some View { + let binding: Binding = Binding { isLoading[alert] == true ? .loading : subscription.alerts.contains(alert) ? .on : .off } set: { newValue in isLoading[alert] = newValue == .loading } + return AsyncToggle(titleKey, mode: binding) { + await updateSubscription(alert: alert, isOn: $0) + } } - private func onChange(alert: PushSubscription.Alerts, value: Bool) async { + private func updateSubscription(alert: PushSubscription.Alerts, isOn: Bool) async { var newAlerts = subscription.alerts - if value { + if isOn { newAlerts.insert(alert) } else { newAlerts.remove(alert)