TripOptionCard improvements: - Replace horizontal route with vertical layout (start → end with arrow) - Remove rank badges (1, 2, 3, etc.) - Split stats into two rows: cities/miles and sports with game counts - Clear selection when navigating back from detail view Settings cleanup: - Remove unused settings (preferred game time, playoff games, notifications) - Convert remaining settings to sliders Planning fixes: - Fix multi-day driving calculation in canTransition - Remove over-restrictive trip rejection in TravelEstimator - Clear games cache when sport selection changes UI polish: - RoutePreviewStrip shows all cities (abbreviated) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
215 lines
6.0 KiB
Swift
215 lines
6.0 KiB
Swift
//
|
|
// SettingsView.swift
|
|
// SportsTime
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SettingsView: View {
|
|
@State private var viewModel = SettingsViewModel()
|
|
@State private var showResetConfirmation = false
|
|
|
|
var body: some View {
|
|
List {
|
|
// Sports Preferences
|
|
sportsSection
|
|
|
|
// Travel Preferences
|
|
travelSection
|
|
|
|
// Data Sync
|
|
dataSection
|
|
|
|
// About
|
|
aboutSection
|
|
|
|
// Reset
|
|
resetSection
|
|
}
|
|
.navigationTitle("Settings")
|
|
.alert("Reset Settings", isPresented: $showResetConfirmation) {
|
|
Button("Cancel", role: .cancel) { }
|
|
Button("Reset", role: .destructive) {
|
|
viewModel.resetToDefaults()
|
|
}
|
|
} message: {
|
|
Text("This will reset all settings to their default values.")
|
|
}
|
|
}
|
|
|
|
// MARK: - Sports Section
|
|
|
|
private var sportsSection: some View {
|
|
Section {
|
|
ForEach(Sport.supported) { sport in
|
|
Toggle(isOn: Binding(
|
|
get: { viewModel.selectedSports.contains(sport) },
|
|
set: { _ in viewModel.toggleSport(sport) }
|
|
)) {
|
|
Label {
|
|
Text(sport.displayName)
|
|
} icon: {
|
|
Image(systemName: sport.iconName)
|
|
.foregroundStyle(sportColor(for: sport))
|
|
}
|
|
}
|
|
}
|
|
} header: {
|
|
Text("Favorite Sports")
|
|
} footer: {
|
|
Text("Selected sports will be shown by default in schedules and trip planning.")
|
|
}
|
|
}
|
|
|
|
// MARK: - Travel Section
|
|
|
|
private var travelSection: some View {
|
|
Section {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
HStack {
|
|
Text("Max Driving Per Day")
|
|
Spacer()
|
|
Text("\(viewModel.maxDrivingHoursPerDay) hours")
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
Slider(
|
|
value: Binding(
|
|
get: { Double(viewModel.maxDrivingHoursPerDay) },
|
|
set: { viewModel.maxDrivingHoursPerDay = Int($0) }
|
|
),
|
|
in: 2...12,
|
|
step: 1
|
|
)
|
|
}
|
|
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
HStack {
|
|
Text("Trip Options to Show")
|
|
Spacer()
|
|
Text("\(viewModel.maxTripOptions)")
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
Slider(
|
|
value: Binding(
|
|
get: { Double(viewModel.maxTripOptions) },
|
|
set: { viewModel.maxTripOptions = Int($0) }
|
|
),
|
|
in: 1...20,
|
|
step: 1
|
|
)
|
|
}
|
|
} header: {
|
|
Text("Travel Preferences")
|
|
} footer: {
|
|
Text("Trips will be optimized to keep daily driving within this limit.")
|
|
}
|
|
}
|
|
|
|
// MARK: - Data Section
|
|
|
|
private var dataSection: some View {
|
|
Section {
|
|
Button {
|
|
Task {
|
|
await viewModel.syncSchedules()
|
|
}
|
|
} label: {
|
|
HStack {
|
|
Label("Sync Schedules", systemImage: "arrow.triangle.2.circlepath")
|
|
|
|
Spacer()
|
|
|
|
if viewModel.isSyncing {
|
|
ProgressView()
|
|
}
|
|
}
|
|
}
|
|
.disabled(viewModel.isSyncing)
|
|
|
|
if let lastSync = viewModel.lastSyncDate {
|
|
HStack {
|
|
Text("Last Sync")
|
|
Spacer()
|
|
Text(lastSync, style: .relative)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
|
|
if let error = viewModel.syncError {
|
|
HStack {
|
|
Image(systemName: "exclamationmark.triangle")
|
|
.foregroundStyle(.red)
|
|
Text(error)
|
|
.font(.caption)
|
|
.foregroundStyle(.red)
|
|
}
|
|
}
|
|
} header: {
|
|
Text("Data")
|
|
} footer: {
|
|
#if targetEnvironment(simulator)
|
|
Text("Using stub data (Simulator mode)")
|
|
#else
|
|
Text("Schedule data is synced from CloudKit.")
|
|
#endif
|
|
}
|
|
}
|
|
|
|
// MARK: - About Section
|
|
|
|
private var aboutSection: some View {
|
|
Section {
|
|
HStack {
|
|
Text("Version")
|
|
Spacer()
|
|
Text("\(viewModel.appVersion) (\(viewModel.buildNumber))")
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
|
|
Link(destination: URL(string: "https://sportstime.app/privacy")!) {
|
|
Label("Privacy Policy", systemImage: "hand.raised")
|
|
}
|
|
|
|
Link(destination: URL(string: "https://sportstime.app/terms")!) {
|
|
Label("Terms of Service", systemImage: "doc.text")
|
|
}
|
|
|
|
Link(destination: URL(string: "mailto:support@sportstime.app")!) {
|
|
Label("Contact Support", systemImage: "envelope")
|
|
}
|
|
} header: {
|
|
Text("About")
|
|
}
|
|
}
|
|
|
|
// MARK: - Reset Section
|
|
|
|
private var resetSection: some View {
|
|
Section {
|
|
Button(role: .destructive) {
|
|
showResetConfirmation = true
|
|
} label: {
|
|
Label("Reset to Defaults", systemImage: "arrow.counterclockwise")
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Helpers
|
|
|
|
private func sportColor(for sport: Sport) -> Color {
|
|
switch sport {
|
|
case .mlb: return .red
|
|
case .nba: return .orange
|
|
case .nhl: return .blue
|
|
case .nfl: return .green
|
|
case .mls: return .purple
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
NavigationStack {
|
|
SettingsView()
|
|
}
|
|
}
|