Notification type toggles
This commit is contained in:
parent
f02afaac26
commit
241e6f7e3a
|
@ -40,9 +40,14 @@ private struct PushSubscriptionSettingsView: View {
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .prefsAvatar) {
|
VStack(alignment: .prefsAvatar) {
|
||||||
AsyncToggle("Mentions", mode: alertsBinding(for: .mention)) {
|
toggle("All", alert: [.mention, .favorite, .reblog, .follow, .followRequest, .poll, .update])
|
||||||
await onChange(alert: .mention, value: $0)
|
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
|
// this is the default value of the alignment guide, but this modifier is loading bearing
|
||||||
.alignmentGuide(.prefsAvatar, computeValue: { dimension in
|
.alignmentGuide(.prefsAvatar, computeValue: { dimension in
|
||||||
|
@ -52,17 +57,20 @@ private struct PushSubscriptionSettingsView: View {
|
||||||
.padding(.leading, 38)
|
.padding(.leading, 38)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func alertsBinding(for alert: PushSubscription.Alerts) -> Binding<AsyncToggle.Mode> {
|
private func toggle(_ titleKey: LocalizedStringKey, alert: PushSubscription.Alerts) -> some View {
|
||||||
return Binding {
|
let binding: Binding<AsyncToggle.Mode> = Binding {
|
||||||
isLoading[alert] == true ? .loading : subscription.alerts.contains(alert) ? .on : .off
|
isLoading[alert] == true ? .loading : subscription.alerts.contains(alert) ? .on : .off
|
||||||
} set: { newValue in
|
} set: { newValue in
|
||||||
isLoading[alert] = newValue == .loading
|
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
|
var newAlerts = subscription.alerts
|
||||||
if value {
|
if isOn {
|
||||||
newAlerts.insert(alert)
|
newAlerts.insert(alert)
|
||||||
} else {
|
} else {
|
||||||
newAlerts.remove(alert)
|
newAlerts.remove(alert)
|
||||||
|
|
Loading…
Reference in New Issue