Files
mayday/Mayday/Views/Settings/SettingsView.swift
T
copilot-swe-agent[bot] 597787a6c9 fix: address all PR review comments
- HTTPClient: replace isRefreshing bool with shared Task to safely
  coalesce concurrent 401 refresh attempts; surface JSON serialization
  error instead of silently dropping request body
- AuthService.logout: always clear Keychain tokens via defer, even when
  refresh token is absent, preventing stale access token
- NotificationsAPIService: remove updateAppBadge (UIKit call moved to
  @MainActor NotificationsViewModel); drop unused UIKit import
- NotificationsViewModel: guard startPolling() against duplicate tasks;
  update badge directly on @MainActor instead of hopping to actor
- VerifyEmailView: replace Timer (never invalidated) with async Task
  cancelled in .onDisappear
- NotificationsView: use Text(date, style: .relative) — auto-updates
  without custom formatter; remove duplicate Date extension
- SettingsView: handle logoutAll errors explicitly with alert instead of
  silently proceeding with local logout
- MaydayLiveActivity/Info.plist: add NSExtensionPrincipalClass so the
  widget extension is discoverable by the system
- Live Activity widget: replace frozen duration(from:) with
  Text(date, style: .timer); replace frozen relativeFormatted with
  Text(date, style: .relative); localize status badge to Russian

Co-authored-by: robonen <26167508+robonen@users.noreply.github.com>
2026-03-13 23:29:19 +00:00

112 lines
4.0 KiB
Swift

import SwiftUI
struct SettingsView: View {
@EnvironmentObject var authViewModel: AuthViewModel
@StateObject private var viewModel = SettingsViewModel()
@Environment(\.dismiss) var dismiss
@State private var showChangePassword = false
@State private var showSessions = false
@State private var showLogoutAllConfirm = false
@State private var logoutAllError: String?
var body: some View {
NavigationStack {
Form {
Section("Аккаунт") {
if let user = authViewModel.currentUser {
LabeledContent("Email", value: user.email)
}
}
Section {
Button("Сменить пароль") {
showChangePassword = true
}
Button {
if let url = URL(string: UIApplication.openNotificationSettingsURLString) {
UIApplication.shared.open(url)
}
} label: {
Label("Push-уведомления", systemImage: "bell.badge")
.foregroundStyle(.primary)
}
}
Section {
Button {
showSessions = true
} label: {
HStack {
Text("Активные сессии")
Spacer()
if !viewModel.sessions.isEmpty {
Text("(\(viewModel.sessions.count))")
.foregroundStyle(.secondary)
}
Image(systemName: "chevron.right")
.foregroundStyle(.secondary)
}
}
.foregroundStyle(.primary)
}
Section {
Button("Выйти из аккаунта", role: .destructive) {
Task { await authViewModel.logout() }
}
Button("Выйти на всех устройствах", role: .destructive) {
showLogoutAllConfirm = true
}
}
}
.navigationTitle("Настройки")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("Готово") { dismiss() }
}
}
.sheet(isPresented: $showChangePassword) {
ChangePasswordView()
}
.sheet(isPresented: $showSessions) {
SessionsView()
.environmentObject(viewModel)
}
.confirmationDialog(
"Выйти на всех устройствах?",
isPresented: $showLogoutAllConfirm,
titleVisibility: .visible
) {
Button("Выйти везде", role: .destructive) {
Task {
do {
_ = try await NotificationsAPIService.shared.logoutAll()
await authViewModel.logout()
} catch {
logoutAllError = error.localizedDescription
}
}
}
Button("Отмена", role: .cancel) {}
}
.alert(
"Ошибка",
isPresented: Binding(
get: { logoutAllError != nil },
set: { if !$0 { logoutAllError = nil } }
)
) {
Button("OK") { logoutAllError = nil }
} message: {
Text(logoutAllError ?? "")
}
.task {
await viewModel.loadSessions()
}
}
}
}