Notification type toggles
This commit is contained in:
parent
f02afaac26
commit
241e6f7e3a
|
@ -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<AsyncToggle.Mode> {
|
||||
return Binding {
|
||||
private func toggle(_ titleKey: LocalizedStringKey, alert: PushSubscription.Alerts) -> some View {
|
||||
let binding: Binding<AsyncToggle.Mode> = 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)
|
||||
|
|
Loading…
Reference in New Issue