import SwiftUI /// Settings-Sheet aus AccountView. Heute: Daily-Reminder-Konfiguration. struct SettingsView: View { @State private var notifications = NotificationManager() @State private var reminderDate: Date = .now @State private var requestingAuth = false var body: some View { Form { Section("Tägliche Erinnerung") { Toggle("Erinnerung aktiv", isOn: Binding( get: { notifications.remindersEnabled }, set: { newValue in notifications.remindersEnabled = newValue Task { if newValue, notifications.authorization != .authorized { requestingAuth = true _ = await notifications.requestAuthorization() requestingAuth = false } await notifications.reschedule() } } )) .disabled(requestingAuth) if notifications.remindersEnabled { DatePicker( "Uhrzeit", selection: $reminderDate, displayedComponents: .hourAndMinute ) .onChange(of: reminderDate) { _, newValue in let cal = Calendar.current notifications.reminderHour = cal.component(.hour, from: newValue) notifications.reminderMinute = cal.component(.minute, from: newValue) Task { await notifications.reschedule() } } } if notifications.authorization == .denied { Label( "Benachrichtigungen sind in den iOS-Einstellungen blockiert.", systemImage: "exclamationmark.circle" ) .font(.caption) .foregroundStyle(CardsTheme.warning) } } Section("Marketplace") { NavigationLink { BlockedAuthorsView() } label: { Label("Blockierte Authors", systemImage: "hand.raised") } } Section("Über") { LabeledContent("Server", value: "cardecky-api.mana.how") LabeledContent("Auth", value: "auth.mana.how") } } .navigationTitle("Einstellungen") #if os(iOS) .navigationBarTitleDisplayMode(.inline) #endif .task { await notifications.refreshAuthorization() var comp = DateComponents() comp.hour = notifications.reminderHour comp.minute = notifications.reminderMinute reminderDate = Calendar.current.date(from: comp) ?? .now } } }