Redesign trip option cards and fix various UI/planning issues

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>
This commit is contained in:
Trey t
2026-01-07 21:05:25 -06:00
parent 4184af60b5
commit 5bbfd30a70
12 changed files with 230 additions and 208 deletions

View File

@@ -20,15 +20,7 @@ final class SettingsViewModel {
didSet { savePreferences() }
}
var preferredGameTime: PreferredGameTime {
didSet { savePreferences() }
}
var includePlayoffGames: Bool {
didSet { savePreferences() }
}
var notificationsEnabled: Bool {
var maxTripOptions: Int {
didSet { savePreferences() }
}
@@ -56,19 +48,12 @@ final class SettingsViewModel {
self.selectedSports = Set(Sport.supported)
}
// Travel preferences - use local variable to avoid self access before init complete
// Travel preferences
let savedDrivingHours = defaults.integer(forKey: "maxDrivingHoursPerDay")
self.maxDrivingHoursPerDay = savedDrivingHours == 0 ? 8 : savedDrivingHours
if let timeRaw = defaults.string(forKey: "preferredGameTime"),
let time = PreferredGameTime(rawValue: timeRaw) {
self.preferredGameTime = time
} else {
self.preferredGameTime = .evening
}
self.includePlayoffGames = defaults.object(forKey: "includePlayoffGames") as? Bool ?? true
self.notificationsEnabled = defaults.object(forKey: "notificationsEnabled") as? Bool ?? true
let savedMaxTripOptions = defaults.integer(forKey: "maxTripOptions")
self.maxTripOptions = savedMaxTripOptions == 0 ? 10 : savedMaxTripOptions
// Last sync
self.lastSyncDate = defaults.object(forKey: "lastSyncDate") as? Date
@@ -110,9 +95,7 @@ final class SettingsViewModel {
func resetToDefaults() {
selectedSports = Set(Sport.supported)
maxDrivingHoursPerDay = 8
preferredGameTime = .evening
includePlayoffGames = true
notificationsEnabled = true
maxTripOptions = 10
}
// MARK: - Persistence
@@ -121,34 +104,6 @@ final class SettingsViewModel {
let defaults = UserDefaults.standard
defaults.set(selectedSports.map(\.rawValue), forKey: "selectedSports")
defaults.set(maxDrivingHoursPerDay, forKey: "maxDrivingHoursPerDay")
defaults.set(preferredGameTime.rawValue, forKey: "preferredGameTime")
defaults.set(includePlayoffGames, forKey: "includePlayoffGames")
defaults.set(notificationsEnabled, forKey: "notificationsEnabled")
}
}
// MARK: - Supporting Types
enum PreferredGameTime: String, CaseIterable, Identifiable {
case any = "any"
case afternoon = "afternoon"
case evening = "evening"
var id: String { rawValue }
var displayName: String {
switch self {
case .any: return "Any Time"
case .afternoon: return "Afternoon"
case .evening: return "Evening"
}
}
var description: String {
switch self {
case .any: return "No preference"
case .afternoon: return "1 PM - 5 PM"
case .evening: return "6 PM - 10 PM"
}
defaults.set(maxTripOptions, forKey: "maxTripOptions")
}
}

View File

@@ -17,12 +17,6 @@ struct SettingsView: View {
// Travel Preferences
travelSection
// Game Preferences
gamePreferencesSection
// Notifications
notificationsSection
// Data Sync
dataSection
@@ -71,13 +65,38 @@ struct SettingsView: View {
private var travelSection: some View {
Section {
Stepper(value: $viewModel.maxDrivingHoursPerDay, in: 2...12) {
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")
@@ -86,39 +105,6 @@ struct SettingsView: View {
}
}
// MARK: - Game Preferences Section
private var gamePreferencesSection: some View {
Section {
Picker("Preferred Game Time", selection: $viewModel.preferredGameTime) {
ForEach(PreferredGameTime.allCases) { time in
VStack(alignment: .leading) {
Text(time.displayName)
}
.tag(time)
}
}
Toggle("Include Playoff Games", isOn: $viewModel.includePlayoffGames)
} header: {
Text("Game Preferences")
} footer: {
Text("These preferences affect trip optimization.")
}
}
// MARK: - Notifications Section
private var notificationsSection: some View {
Section {
Toggle("Schedule Updates", isOn: $viewModel.notificationsEnabled)
} header: {
Text("Notifications")
} footer: {
Text("Get notified when games in your trips are rescheduled.")
}
}
// MARK: - Data Section
private var dataSection: some View {

View File

@@ -47,7 +47,15 @@ final class TripCreationViewModel {
var endLocation: LocationInput?
// Sports
var selectedSports: Set<Sport> = [.mlb]
var selectedSports: Set<Sport> = [.mlb] {
didSet {
// Clear cached games when sports selection changes
if selectedSports != oldValue {
availableGames = []
games = []
}
}
}
// Dates
var startDate: Date = Date()
@@ -266,6 +274,10 @@ final class TripCreationViewModel {
await loadScheduleData()
}
// Read max trip options from settings (default 10)
let savedMaxOptions = UserDefaults.standard.integer(forKey: "maxTripOptions")
let maxTripOptions = savedMaxOptions > 0 ? min(20, savedMaxOptions) : 10
// Build preferences
let preferences = TripPreferences(
planningMode: planningMode,
@@ -285,7 +297,8 @@ final class TripCreationViewModel {
needsEVCharging: needsEVCharging,
lodgingType: lodgingType,
numberOfDrivers: numberOfDrivers,
maxDrivingHoursPerDriver: maxDrivingHoursPerDriver
maxDrivingHoursPerDriver: maxDrivingHoursPerDriver,
maxTripOptions: maxTripOptions
)
// Build planning request
@@ -447,6 +460,9 @@ final class TripCreationViewModel {
/// Convert an itinerary option to a Trip (public for use by TripOptionsView)
func convertOptionToTrip(_ option: ItineraryOption) -> Trip {
let savedMaxOptions = UserDefaults.standard.integer(forKey: "maxTripOptions")
let maxOptions = savedMaxOptions > 0 ? min(20, savedMaxOptions) : 10
let preferences = currentPreferences ?? TripPreferences(
planningMode: planningMode,
startLocation: nil,
@@ -465,7 +481,8 @@ final class TripCreationViewModel {
needsEVCharging: needsEVCharging,
lodgingType: lodgingType,
numberOfDrivers: numberOfDrivers,
maxDrivingHoursPerDriver: maxDrivingHoursPerDriver
maxDrivingHoursPerDriver: maxDrivingHoursPerDriver,
maxTripOptions: maxOptions
)
return convertToTrip(option: option, preferences: preferences)
}

View File

@@ -1106,10 +1106,9 @@ struct TripOptionsView: View {
.padding(.bottom, Theme.Spacing.sm)
// Options list
ForEach(Array(sortedOptions.enumerated()), id: \.element.id) { index, option in
ForEach(sortedOptions) { option in
TripOptionCard(
option: option,
rank: index + 1,
games: games,
onSelect: {
selectedTrip = convertToTrip(option)
@@ -1129,6 +1128,11 @@ struct TripOptionsView: View {
TripDetailView(trip: trip, games: games)
}
}
.onChange(of: showTripDetail) { _, isShowing in
if !isShowing {
selectedTrip = nil
}
}
}
private var sortPicker: some View {
@@ -1168,7 +1172,6 @@ struct TripOptionsView: View {
struct TripOptionCard: View {
let option: ItineraryOption
let rank: Int
let games: [UUID: RichGame]
let onSelect: () -> Void
@Environment(\.colorScheme) private var colorScheme
@@ -1184,34 +1187,50 @@ struct TripOptionCard: View {
option.stops.flatMap { $0.games }.count
}
private var routeDescription: String {
if uniqueCities.count <= 2 {
return uniqueCities.joined(separator: "")
private var uniqueSports: [Sport] {
let gameIds = option.stops.flatMap { $0.games }
let sports = gameIds.compactMap { games[$0]?.game.sport }
return Array(Set(sports)).sorted { $0.rawValue < $1.rawValue }
}
private var gamesPerSport: [(sport: Sport, count: Int)] {
let gameIds = option.stops.flatMap { $0.games }
var countsBySport: [Sport: Int] = [:]
for gameId in gameIds {
if let sport = games[gameId]?.game.sport {
countsBySport[sport, default: 0] += 1
}
}
return "\(uniqueCities.first ?? "")\(uniqueCities.count - 2) stops → \(uniqueCities.last ?? "")"
return countsBySport.sorted { $0.key.rawValue < $1.key.rawValue }
.map { (sport: $0.key, count: $0.value) }
}
var body: some View {
Button(action: onSelect) {
HStack(spacing: Theme.Spacing.md) {
// Left: Rank badge
Text("\(rank)")
.font(.system(size: 18, weight: .bold))
.foregroundStyle(.white)
.frame(width: 36, height: 36)
.background(rank == 1 ? Theme.warmOrange : Theme.textMuted(colorScheme))
.clipShape(Circle())
// Middle: Route info
// Route info
VStack(alignment: .leading, spacing: 6) {
Text(routeDescription)
.font(.system(size: 16, weight: .semibold))
.foregroundStyle(Theme.textPrimary(colorScheme))
.lineLimit(1)
// Vertical route display
VStack(alignment: .leading, spacing: 0) {
Text(uniqueCities.first ?? "")
.font(.system(size: 15, weight: .semibold))
.foregroundStyle(Theme.textPrimary(colorScheme))
// Stats row
VStack(spacing: 0) {
Text("|")
.font(.system(size: 10))
Image(systemName: "chevron.down")
.font(.system(size: 8, weight: .bold))
}
.foregroundStyle(Theme.warmOrange)
Text(uniqueCities.last ?? "")
.font(.system(size: 15, weight: .semibold))
.foregroundStyle(Theme.textPrimary(colorScheme))
}
// Top stats row: cities and miles
HStack(spacing: 12) {
Label("\(totalGames) games", systemImage: "sportscourt")
Label("\(uniqueCities.count) cities", systemImage: "mappin")
if option.totalDistanceMiles > 0 {
Label("\(Int(option.totalDistanceMiles)) mi", systemImage: "car")
@@ -1220,6 +1239,23 @@ struct TripOptionCard: View {
.font(.system(size: 12))
.foregroundStyle(Theme.textSecondary(colorScheme))
// Bottom row: sports with game counts
HStack(spacing: 6) {
ForEach(gamesPerSport, id: \.sport) { item in
HStack(spacing: 3) {
Image(systemName: item.sport.iconName)
.font(.system(size: 9))
Text("\(item.sport.rawValue.uppercased()) \(item.count)")
.font(.system(size: 9, weight: .semibold))
}
.padding(.horizontal, 6)
.padding(.vertical, 3)
.background(item.sport.themeColor.opacity(0.15))
.foregroundStyle(item.sport.themeColor)
.clipShape(Capsule())
}
}
// AI-generated description (after stats)
if let description = aiDescription {
Text(description)
@@ -1250,7 +1286,7 @@ struct TripOptionCard: View {
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
.overlay {
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
.stroke(rank == 1 ? Theme.warmOrange : Theme.surfaceGlow(colorScheme), lineWidth: rank == 1 ? 2 : 1)
.stroke(Theme.surfaceGlow(colorScheme), lineWidth: 1)
}
}
.buttonStyle(.plain)