2026-06-18 22:17:41 +03:00
|
|
|
// SettingsView.swift
|
|
|
|
|
// Jarvis — settings hub: Notifications, Connectivity, and server info.
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
2026-06-20 14:25:39 +03:00
|
|
|
import SwiftData
|
2026-06-18 22:17:41 +03:00
|
|
|
|
|
|
|
|
struct SettingsView: View {
|
|
|
|
|
@EnvironmentObject var settings: ServerSettings
|
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
2026-06-20 14:25:39 +03:00
|
|
|
@Environment(\.modelContext) private var modelContext
|
|
|
|
|
@Query private var cachedStories: [CachedStory]
|
|
|
|
|
@Query private var cachedArticles: [CachedArticle]
|
|
|
|
|
@State private var showClearConfirm = false
|
2026-06-18 22:17:41 +03:00
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
NavigationStack {
|
|
|
|
|
ZStack {
|
|
|
|
|
Color.black.ignoresSafeArea()
|
|
|
|
|
ScrollView {
|
|
|
|
|
VStack(alignment: .leading, spacing: 26) {
|
|
|
|
|
header
|
|
|
|
|
|
|
|
|
|
group("GENERAL") {
|
|
|
|
|
NavigationLink { NotificationsView() } label: {
|
|
|
|
|
row(icon: "bell.badge", title: "Notifications",
|
|
|
|
|
subtitle: "Briefings & breaking alerts")
|
|
|
|
|
}
|
|
|
|
|
divider
|
|
|
|
|
NavigationLink { ConnectivityView() } label: {
|
|
|
|
|
row(icon: "globe", title: "Connectivity",
|
|
|
|
|
subtitle: "Server address & Tailscale remote")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
group("PLATFORM") {
|
|
|
|
|
row(icon: "server.rack", title: settings.host ?? "Not configured",
|
|
|
|
|
subtitle: "Connected server", chevron: false)
|
|
|
|
|
}
|
2026-06-20 14:25:39 +03:00
|
|
|
|
|
|
|
|
group("STORAGE") {
|
|
|
|
|
Button { showClearConfirm = true } label: {
|
|
|
|
|
row(icon: "trash", title: "Clear offline cache",
|
|
|
|
|
subtitle: "\(cachedStories.count) stories · \(cachedArticles.count) articles · keeps saved",
|
|
|
|
|
chevron: false, tint: Color(hex: "C25555"))
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-18 22:17:41 +03:00
|
|
|
}
|
|
|
|
|
.padding(.horizontal, 20)
|
|
|
|
|
.padding(.vertical, 12)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.navigationBarHidden(true)
|
|
|
|
|
}
|
|
|
|
|
.presentationDragIndicator(.visible)
|
2026-06-20 14:25:39 +03:00
|
|
|
.confirmationDialog("Clear offline cache?", isPresented: $showClearConfirm, titleVisibility: .visible) {
|
|
|
|
|
Button("Clear cache", role: .destructive) { CacheMaintenance.clear(modelContext) }
|
|
|
|
|
Button("Cancel", role: .cancel) {}
|
|
|
|
|
} message: {
|
|
|
|
|
Text("Removes cached stories, articles, and read/seen history. Your saved stories are kept.")
|
|
|
|
|
}
|
2026-06-18 22:17:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private var header: some View {
|
|
|
|
|
HStack {
|
|
|
|
|
Text("Settings").font(.system(size: 22, weight: .heavy)).foregroundStyle(.white)
|
|
|
|
|
Spacer()
|
|
|
|
|
Button { dismiss() } label: {
|
|
|
|
|
Image(systemName: "xmark").font(.system(size: 15, weight: .bold))
|
|
|
|
|
.foregroundStyle(Color(hex: "888888")).frame(width: 44, height: 44)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.padding(.top, 8)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func group<C: View>(_ label: String, @ViewBuilder _ content: () -> C) -> some View {
|
|
|
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
|
|
|
Text(label).font(.system(size: 11, weight: .bold, design: .monospaced))
|
|
|
|
|
.kerning(0.8).foregroundStyle(Color(hex: "555555"))
|
|
|
|
|
VStack(spacing: 0) { content() }
|
|
|
|
|
.background(Palette.surface)
|
|
|
|
|
.clipShape(RoundedRectangle(cornerRadius: 14))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-20 14:25:39 +03:00
|
|
|
private func row(icon: String, title: String, subtitle: String,
|
|
|
|
|
chevron: Bool = true, tint: Color = .white) -> some View {
|
2026-06-18 22:17:41 +03:00
|
|
|
HStack(spacing: 14) {
|
2026-06-20 14:25:39 +03:00
|
|
|
Image(systemName: icon).font(.system(size: 18))
|
|
|
|
|
.foregroundStyle(tint == .white ? Color(hex: "999999") : tint).frame(width: 26)
|
2026-06-18 22:17:41 +03:00
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
2026-06-20 14:25:39 +03:00
|
|
|
Text(title).font(.system(size: 16, weight: .heavy)).foregroundStyle(tint).lineLimit(1)
|
2026-06-18 22:17:41 +03:00
|
|
|
Text(subtitle).font(.system(size: 12)).foregroundStyle(Color(hex: "888888")).lineLimit(1)
|
|
|
|
|
}
|
|
|
|
|
Spacer()
|
|
|
|
|
if chevron {
|
|
|
|
|
Image(systemName: "chevron.right").font(.system(size: 13, weight: .bold))
|
|
|
|
|
.foregroundStyle(Color(hex: "555555"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.padding(.horizontal, 14).padding(.vertical, 14).frame(minHeight: 44)
|
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private var divider: some View {
|
|
|
|
|
Rectangle().fill(Palette.surface2).frame(height: 1).padding(.leading, 54)
|
|
|
|
|
}
|
|
|
|
|
}
|