fix(wizard): improve UX with step reordering and UI polish
- Reorder wizard steps: dates before sports (enables availability check) - Add contentShape(Rectangle()) for full tap targets on all cards - Fix route preference showing preselected value - Fix sport cards having inconsistent heights - Speed up step reveal animation (0.3s → 0.15s) - Add debounced scroll delay to avoid interrupting selection Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -62,16 +62,16 @@ final class TripWizardViewModel {
|
|||||||
|
|
||||||
var isPlanningModeStepVisible: Bool { true }
|
var isPlanningModeStepVisible: Bool { true }
|
||||||
|
|
||||||
var isSportsStepVisible: Bool {
|
var isDatesStepVisible: Bool {
|
||||||
planningMode != nil
|
planningMode != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var isDatesStepVisible: Bool {
|
var isSportsStepVisible: Bool {
|
||||||
isSportsStepVisible && !selectedSports.isEmpty
|
isDatesStepVisible && hasSetDates
|
||||||
}
|
}
|
||||||
|
|
||||||
var isRegionsStepVisible: Bool {
|
var isRegionsStepVisible: Bool {
|
||||||
isDatesStepVisible && hasSetDates
|
isSportsStepVisible && !selectedSports.isEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
var isRoutePreferenceStepVisible: Bool {
|
var isRoutePreferenceStepVisible: Bool {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// DatesStep.swift
|
// DatesStep.swift
|
||||||
// SportsTime
|
// SportsTime
|
||||||
//
|
//
|
||||||
// Step 3 of the trip wizard - select travel dates.
|
// Step 2 of the trip wizard - select travel dates.
|
||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
@@ -18,51 +18,24 @@ struct DatesStep: View {
|
|||||||
VStack(alignment: .leading, spacing: Theme.Spacing.md) {
|
VStack(alignment: .leading, spacing: Theme.Spacing.md) {
|
||||||
StepHeader(
|
StepHeader(
|
||||||
title: "When would you like to travel?",
|
title: "When would you like to travel?",
|
||||||
subtitle: "Pick your trip dates"
|
subtitle: "Tap to select start and end dates"
|
||||||
)
|
)
|
||||||
|
|
||||||
VStack(spacing: Theme.Spacing.md) {
|
DateRangePicker(
|
||||||
DatePicker(
|
startDate: $startDate,
|
||||||
"Start Date",
|
endDate: $endDate
|
||||||
selection: $startDate,
|
|
||||||
in: Date()...,
|
|
||||||
displayedComponents: .date
|
|
||||||
)
|
)
|
||||||
.datePickerStyle(.compact)
|
.onChange(of: startDate) { _, _ in
|
||||||
.onChange(of: startDate) { _, newValue in
|
// Only mark as complete when user has selected both dates (end > start)
|
||||||
// Ensure end date is after start date
|
updateHasSetDates()
|
||||||
if endDate < newValue {
|
|
||||||
endDate = newValue.addingTimeInterval(86400)
|
|
||||||
}
|
|
||||||
hasSetDates = true
|
|
||||||
onDatesChanged()
|
onDatesChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
DatePicker(
|
|
||||||
"End Date",
|
|
||||||
selection: $endDate,
|
|
||||||
in: startDate...,
|
|
||||||
displayedComponents: .date
|
|
||||||
)
|
|
||||||
.datePickerStyle(.compact)
|
|
||||||
.onChange(of: endDate) { _, _ in
|
.onChange(of: endDate) { _, _ in
|
||||||
hasSetDates = true
|
// Only mark as complete when user has selected both dates (end > start)
|
||||||
|
updateHasSetDates()
|
||||||
onDatesChanged()
|
onDatesChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(Theme.Spacing.sm)
|
|
||||||
.background(Theme.cardBackgroundElevated(colorScheme))
|
|
||||||
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
|
|
||||||
|
|
||||||
// Trip duration indicator
|
|
||||||
HStack {
|
|
||||||
Image(systemName: "calendar.badge.clock")
|
|
||||||
.foregroundStyle(Theme.textMuted(colorScheme))
|
|
||||||
Text(durationText)
|
|
||||||
.font(.subheadline)
|
|
||||||
.foregroundStyle(Theme.textSecondary(colorScheme))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(Theme.Spacing.lg)
|
.padding(Theme.Spacing.lg)
|
||||||
.background(Theme.cardBackground(colorScheme))
|
.background(Theme.cardBackground(colorScheme))
|
||||||
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.large))
|
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.large))
|
||||||
@@ -72,15 +45,12 @@ struct DatesStep: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var durationText: String {
|
private func updateHasSetDates() {
|
||||||
let days = Calendar.current.dateComponents([.day], from: startDate, to: endDate).day ?? 0
|
// User must select both start and end dates (end date must be after start)
|
||||||
if days == 0 {
|
let calendar = Calendar.current
|
||||||
return "Same day trip"
|
let startDay = calendar.startOfDay(for: startDate)
|
||||||
} else if days == 1 {
|
let endDay = calendar.startOfDay(for: endDate)
|
||||||
return "1 day trip"
|
hasSetDates = endDay > startDay
|
||||||
} else {
|
|
||||||
return "\(days) day trip"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ struct PlanningModeStep: View {
|
|||||||
|
|
||||||
VStack(spacing: Theme.Spacing.sm) {
|
VStack(spacing: Theme.Spacing.sm) {
|
||||||
ForEach(PlanningMode.allCases) { mode in
|
ForEach(PlanningMode.allCases) { mode in
|
||||||
PlanningModeCard(
|
WizardModeCard(
|
||||||
mode: mode,
|
mode: mode,
|
||||||
isSelected: selection == mode,
|
isSelected: selection == mode,
|
||||||
onTap: { selection = mode }
|
onTap: { selection = mode }
|
||||||
@@ -38,9 +38,9 @@ struct PlanningModeStep: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Planning Mode Card
|
// MARK: - Wizard Mode Card
|
||||||
|
|
||||||
private struct PlanningModeCard: View {
|
private struct WizardModeCard: View {
|
||||||
@Environment(\.colorScheme) private var colorScheme
|
@Environment(\.colorScheme) private var colorScheme
|
||||||
let mode: PlanningMode
|
let mode: PlanningMode
|
||||||
let isSelected: Bool
|
let isSelected: Bool
|
||||||
@@ -74,6 +74,7 @@ private struct PlanningModeCard: View {
|
|||||||
.padding(Theme.Spacing.md)
|
.padding(Theme.Spacing.md)
|
||||||
.background(isSelected ? Theme.warmOrange.opacity(0.1) : Color.clear)
|
.background(isSelected ? Theme.warmOrange.opacity(0.1) : Color.clear)
|
||||||
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
|
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
|
||||||
|
.contentShape(Rectangle())
|
||||||
.overlay(
|
.overlay(
|
||||||
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
|
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
|
||||||
.stroke(isSelected ? Theme.warmOrange : Theme.textMuted(colorScheme).opacity(0.3), lineWidth: isSelected ? 2 : 1)
|
.stroke(isSelected ? Theme.warmOrange : Theme.textMuted(colorScheme).opacity(0.3), lineWidth: isSelected ? 2 : 1)
|
||||||
|
|||||||
@@ -11,38 +11,20 @@ struct RegionsStep: View {
|
|||||||
@Environment(\.colorScheme) private var colorScheme
|
@Environment(\.colorScheme) private var colorScheme
|
||||||
@Binding var selectedRegions: Set<Region>
|
@Binding var selectedRegions: Set<Region>
|
||||||
|
|
||||||
private let columns = [
|
|
||||||
GridItem(.flexible()),
|
|
||||||
GridItem(.flexible())
|
|
||||||
]
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading, spacing: Theme.Spacing.md) {
|
VStack(alignment: .leading, spacing: Theme.Spacing.md) {
|
||||||
StepHeader(
|
StepHeader(
|
||||||
title: "Where do you want to go?",
|
title: "Where do you want to go?",
|
||||||
subtitle: "Select one or more regions"
|
subtitle: "Tap the map to select regions"
|
||||||
)
|
)
|
||||||
|
|
||||||
LazyVGrid(columns: columns, spacing: Theme.Spacing.sm) {
|
RegionMapSelector(
|
||||||
ForEach(Region.allCases.filter { $0 != .crossCountry }) { region in
|
selectedRegions: $selectedRegions,
|
||||||
RegionCard(
|
onToggle: { region in
|
||||||
region: region,
|
toggleRegion(region)
|
||||||
isSelected: selectedRegions.contains(region),
|
}
|
||||||
onTap: { toggleRegion(region) }
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !selectedRegions.isEmpty {
|
|
||||||
HStack {
|
|
||||||
Image(systemName: "mappin.circle.fill")
|
|
||||||
.foregroundStyle(Theme.warmOrange)
|
|
||||||
Text("\(selectedRegions.count) region\(selectedRegions.count == 1 ? "" : "s") selected")
|
|
||||||
.font(.subheadline)
|
|
||||||
.foregroundStyle(Theme.textSecondary(colorScheme))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(Theme.Spacing.lg)
|
.padding(Theme.Spacing.lg)
|
||||||
.background(Theme.cardBackground(colorScheme))
|
.background(Theme.cardBackground(colorScheme))
|
||||||
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.large))
|
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.large))
|
||||||
@@ -61,40 +43,6 @@ struct RegionsStep: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Region Card
|
|
||||||
|
|
||||||
private struct RegionCard: View {
|
|
||||||
@Environment(\.colorScheme) private var colorScheme
|
|
||||||
let region: Region
|
|
||||||
let isSelected: Bool
|
|
||||||
let onTap: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
Button(action: onTap) {
|
|
||||||
VStack(spacing: Theme.Spacing.xs) {
|
|
||||||
Image(systemName: region.iconName)
|
|
||||||
.font(.title)
|
|
||||||
.foregroundStyle(isSelected ? Theme.warmOrange : Theme.textSecondary(colorScheme))
|
|
||||||
|
|
||||||
Text(region.shortName)
|
|
||||||
.font(.caption)
|
|
||||||
.fontWeight(.medium)
|
|
||||||
.foregroundStyle(isSelected ? Theme.warmOrange : Theme.textPrimary(colorScheme))
|
|
||||||
.multilineTextAlignment(.center)
|
|
||||||
}
|
|
||||||
.frame(maxWidth: .infinity)
|
|
||||||
.padding(.vertical, Theme.Spacing.md)
|
|
||||||
.background(isSelected ? Theme.warmOrange.opacity(0.1) : Color.clear)
|
|
||||||
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
|
|
||||||
.overlay(
|
|
||||||
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
|
|
||||||
.stroke(isSelected ? Theme.warmOrange : Theme.textMuted(colorScheme).opacity(0.3), lineWidth: isSelected ? 2 : 1)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Preview
|
// MARK: - Preview
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ private struct OptionButton: View {
|
|||||||
.padding(Theme.Spacing.md)
|
.padding(Theme.Spacing.md)
|
||||||
.background(isSelected ? Theme.warmOrange.opacity(0.1) : Color.clear)
|
.background(isSelected ? Theme.warmOrange.opacity(0.1) : Color.clear)
|
||||||
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
|
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
|
||||||
|
.contentShape(Rectangle())
|
||||||
.overlay(
|
.overlay(
|
||||||
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
|
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
|
||||||
.stroke(isSelected ? Theme.warmOrange : Theme.textMuted(colorScheme).opacity(0.3), lineWidth: isSelected ? 2 : 1)
|
.stroke(isSelected ? Theme.warmOrange : Theme.textMuted(colorScheme).opacity(0.3), lineWidth: isSelected ? 2 : 1)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ struct RoutePreferenceStep: View {
|
|||||||
ForEach(RoutePreference.allCases) { preference in
|
ForEach(RoutePreference.allCases) { preference in
|
||||||
RoutePreferenceCard(
|
RoutePreferenceCard(
|
||||||
preference: preference,
|
preference: preference,
|
||||||
isSelected: routePreference == preference,
|
isSelected: hasSetRoutePreference && routePreference == preference,
|
||||||
onTap: {
|
onTap: {
|
||||||
routePreference = preference
|
routePreference = preference
|
||||||
hasSetRoutePreference = true
|
hasSetRoutePreference = true
|
||||||
@@ -78,6 +78,7 @@ private struct RoutePreferenceCard: View {
|
|||||||
.padding(Theme.Spacing.md)
|
.padding(Theme.Spacing.md)
|
||||||
.background(isSelected ? Theme.warmOrange.opacity(0.1) : Color.clear)
|
.background(isSelected ? Theme.warmOrange.opacity(0.1) : Color.clear)
|
||||||
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
|
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
|
||||||
|
.contentShape(Rectangle())
|
||||||
.overlay(
|
.overlay(
|
||||||
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
|
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
|
||||||
.stroke(isSelected ? Theme.warmOrange : Theme.textMuted(colorScheme).opacity(0.3), lineWidth: isSelected ? 2 : 1)
|
.stroke(isSelected ? Theme.warmOrange : Theme.textMuted(colorScheme).opacity(0.3), lineWidth: isSelected ? 2 : 1)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// SportsStep.swift
|
// SportsStep.swift
|
||||||
// SportsTime
|
// SportsTime
|
||||||
//
|
//
|
||||||
// Step 2 of the trip wizard - select sports leagues.
|
// Step 3 of the trip wizard - select sports leagues.
|
||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
@@ -92,16 +92,15 @@ private struct SportCard: View {
|
|||||||
.fontWeight(.medium)
|
.fontWeight(.medium)
|
||||||
.foregroundStyle(cardColor)
|
.foregroundStyle(cardColor)
|
||||||
|
|
||||||
if !isAvailable {
|
Text(isAvailable ? " " : "No games")
|
||||||
Text("No games")
|
|
||||||
.font(.caption2)
|
.font(.caption2)
|
||||||
.foregroundStyle(Theme.textMuted(colorScheme))
|
.foregroundStyle(Theme.textMuted(colorScheme))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
.padding(.vertical, Theme.Spacing.md)
|
.padding(.vertical, Theme.Spacing.md)
|
||||||
.background(backgroundColor)
|
.background(backgroundColor)
|
||||||
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
|
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
|
||||||
|
.contentShape(Rectangle())
|
||||||
.overlay(
|
.overlay(
|
||||||
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
|
RoundedRectangle(cornerRadius: Theme.CornerRadius.medium)
|
||||||
.stroke(borderColor, lineWidth: isSelected ? 2 : 1)
|
.stroke(borderColor, lineWidth: isSelected ? 2 : 1)
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ struct TripWizardView: View {
|
|||||||
@State private var planningError: String?
|
@State private var planningError: String?
|
||||||
@State private var showError = false
|
@State private var showError = false
|
||||||
|
|
||||||
|
private let planningEngine = TripPlanningEngine()
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
ScrollViewReader { proxy in
|
ScrollViewReader { proxy in
|
||||||
@@ -25,19 +27,7 @@ struct TripWizardView: View {
|
|||||||
PlanningModeStep(selection: $viewModel.planningMode)
|
PlanningModeStep(selection: $viewModel.planningMode)
|
||||||
.id("planningMode")
|
.id("planningMode")
|
||||||
|
|
||||||
// Step 2: Sports (after mode selected)
|
// Step 2: Dates (after mode selected)
|
||||||
if viewModel.isSportsStepVisible {
|
|
||||||
SportsStep(
|
|
||||||
selectedSports: $viewModel.selectedSports,
|
|
||||||
sportAvailability: viewModel.sportAvailability,
|
|
||||||
isLoading: viewModel.isLoadingSportAvailability,
|
|
||||||
canSelectSport: viewModel.canSelectSport
|
|
||||||
)
|
|
||||||
.id("sports")
|
|
||||||
.transition(.move(edge: .bottom).combined(with: .opacity))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 3: Dates (after sport selected)
|
|
||||||
if viewModel.isDatesStepVisible {
|
if viewModel.isDatesStepVisible {
|
||||||
DatesStep(
|
DatesStep(
|
||||||
startDate: $viewModel.startDate,
|
startDate: $viewModel.startDate,
|
||||||
@@ -53,6 +43,18 @@ struct TripWizardView: View {
|
|||||||
.transition(.move(edge: .bottom).combined(with: .opacity))
|
.transition(.move(edge: .bottom).combined(with: .opacity))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Step 3: Sports (after dates set)
|
||||||
|
if viewModel.isSportsStepVisible {
|
||||||
|
SportsStep(
|
||||||
|
selectedSports: $viewModel.selectedSports,
|
||||||
|
sportAvailability: viewModel.sportAvailability,
|
||||||
|
isLoading: viewModel.isLoadingSportAvailability,
|
||||||
|
canSelectSport: viewModel.canSelectSport
|
||||||
|
)
|
||||||
|
.id("sports")
|
||||||
|
.transition(.move(edge: .bottom).combined(with: .opacity))
|
||||||
|
}
|
||||||
|
|
||||||
// Step 4: Regions (after dates set)
|
// Step 4: Regions (after dates set)
|
||||||
if viewModel.isRegionsStepVisible {
|
if viewModel.isRegionsStepVisible {
|
||||||
RegionsStep(selectedRegions: $viewModel.selectedRegions)
|
RegionsStep(selectedRegions: $viewModel.selectedRegions)
|
||||||
@@ -106,12 +108,15 @@ struct TripWizardView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(Theme.Spacing.md)
|
.padding(Theme.Spacing.md)
|
||||||
.animation(.easeInOut(duration: 0.3), value: viewModel.revealState)
|
.animation(.easeInOut(duration: 0.15), value: viewModel.revealState)
|
||||||
}
|
}
|
||||||
.onChange(of: viewModel.revealState) { _, _ in
|
.onChange(of: viewModel.revealState) { _, newState in
|
||||||
// Auto-scroll to newly revealed section
|
// Auto-scroll to newly revealed section after a delay
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
// to avoid interrupting user interactions
|
||||||
withAnimation {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
|
||||||
|
// Only scroll if state hasn't changed (user stopped interacting)
|
||||||
|
guard viewModel.revealState == newState else { return }
|
||||||
|
withAnimation(.easeInOut(duration: 0.25)) {
|
||||||
scrollToLatestStep(proxy: proxy)
|
scrollToLatestStep(proxy: proxy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,7 +135,9 @@ struct TripWizardView: View {
|
|||||||
options: tripOptions,
|
options: tripOptions,
|
||||||
games: [:],
|
games: [:],
|
||||||
preferences: buildPreferences(),
|
preferences: buildPreferences(),
|
||||||
convertToTrip: { _ in nil }
|
convertToTrip: { option in
|
||||||
|
convertOptionToTrip(option)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.alert("Planning Error", isPresented: $showError) {
|
.alert("Planning Error", isPresented: $showError) {
|
||||||
@@ -154,10 +161,10 @@ struct TripWizardView: View {
|
|||||||
proxy.scrollTo("routePreference", anchor: .top)
|
proxy.scrollTo("routePreference", anchor: .top)
|
||||||
} else if viewModel.isRegionsStepVisible {
|
} else if viewModel.isRegionsStepVisible {
|
||||||
proxy.scrollTo("regions", anchor: .top)
|
proxy.scrollTo("regions", anchor: .top)
|
||||||
} else if viewModel.isDatesStepVisible {
|
|
||||||
proxy.scrollTo("dates", anchor: .top)
|
|
||||||
} else if viewModel.isSportsStepVisible {
|
} else if viewModel.isSportsStepVisible {
|
||||||
proxy.scrollTo("sports", anchor: .top)
|
proxy.scrollTo("sports", anchor: .top)
|
||||||
|
} else if viewModel.isDatesStepVisible {
|
||||||
|
proxy.scrollTo("dates", anchor: .top)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,18 +184,21 @@ struct TripWizardView: View {
|
|||||||
endDate: preferences.endDate
|
endDate: preferences.endDate
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Build dictionaries from arrays
|
||||||
|
let teamsById = Dictionary(uniqueKeysWithValues: AppDataProvider.shared.teams.map { ($0.id, $0) })
|
||||||
|
let stadiumsById = Dictionary(uniqueKeysWithValues: AppDataProvider.shared.stadiums.map { ($0.id, $0) })
|
||||||
|
|
||||||
// Build planning request
|
// Build planning request
|
||||||
let request = PlanningRequest(
|
let request = PlanningRequest(
|
||||||
preferences: preferences,
|
preferences: preferences,
|
||||||
availableGames: games,
|
availableGames: games,
|
||||||
teams: AppDataProvider.shared.teams,
|
teams: teamsById,
|
||||||
stadiums: AppDataProvider.shared.stadiums
|
stadiums: stadiumsById
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run planning engine
|
// Run planning engine
|
||||||
let result = await TripPlanningEngine.shared.plan(request: request)
|
let result = planningEngine.planItineraries(request: request)
|
||||||
|
|
||||||
await MainActor.run {
|
|
||||||
switch result {
|
switch result {
|
||||||
case .success(let options):
|
case .success(let options):
|
||||||
if options.isEmpty {
|
if options.isEmpty {
|
||||||
@@ -202,14 +212,11 @@ struct TripWizardView: View {
|
|||||||
planningError = failure.message
|
planningError = failure.message
|
||||||
showError = true
|
showError = true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
await MainActor.run {
|
|
||||||
planningError = error.localizedDescription
|
planningError = error.localizedDescription
|
||||||
showError = true
|
showError = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private func buildPreferences() -> TripPreferences {
|
private func buildPreferences() -> TripPreferences {
|
||||||
TripPreferences(
|
TripPreferences(
|
||||||
@@ -223,6 +230,42 @@ struct TripWizardView: View {
|
|||||||
selectedRegions: viewModel.selectedRegions
|
selectedRegions: viewModel.selectedRegions
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func convertOptionToTrip(_ option: ItineraryOption) -> Trip {
|
||||||
|
let preferences = buildPreferences()
|
||||||
|
|
||||||
|
// Convert ItineraryStops to TripStops
|
||||||
|
let tripStops = option.stops.enumerated().map { index, stop in
|
||||||
|
TripStop(
|
||||||
|
stopNumber: index + 1,
|
||||||
|
city: stop.city,
|
||||||
|
state: stop.state,
|
||||||
|
coordinate: stop.coordinate,
|
||||||
|
arrivalDate: stop.arrivalDate,
|
||||||
|
departureDate: stop.departureDate,
|
||||||
|
games: stop.games,
|
||||||
|
isRestDay: stop.games.isEmpty
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Trip(
|
||||||
|
name: generateTripName(from: tripStops),
|
||||||
|
preferences: preferences,
|
||||||
|
stops: tripStops,
|
||||||
|
travelSegments: option.travelSegments,
|
||||||
|
totalGames: option.totalGames,
|
||||||
|
totalDistanceMeters: option.totalDistanceMiles * 1609.34,
|
||||||
|
totalDrivingSeconds: option.totalDrivingHours * 3600
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func generateTripName(from stops: [TripStop]) -> String {
|
||||||
|
let cities = stops.compactMap { $0.city }.prefix(3)
|
||||||
|
if cities.count <= 1 {
|
||||||
|
return cities.first ?? "Road Trip"
|
||||||
|
}
|
||||||
|
return cities.joined(separator: " → ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Preview
|
// MARK: - Preview
|
||||||
|
|||||||
@@ -45,4 +45,227 @@ final class TripWizardViewModelTests: XCTestCase {
|
|||||||
XCTAssertTrue(viewModel.selectedSports.isEmpty)
|
XCTAssertTrue(viewModel.selectedSports.isEmpty)
|
||||||
XCTAssertFalse(viewModel.hasSetDates)
|
XCTAssertFalse(viewModel.hasSetDates)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Full Flow Integration Tests
|
||||||
|
|
||||||
|
func test_fullWizardFlow_reachesReviewStep() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
|
||||||
|
// Step 1: Select planning mode
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
XCTAssertTrue(viewModel.isSportsStepVisible)
|
||||||
|
|
||||||
|
// Step 2: Select sport
|
||||||
|
viewModel.selectedSports = [.mlb]
|
||||||
|
XCTAssertTrue(viewModel.isDatesStepVisible)
|
||||||
|
|
||||||
|
// Step 3: Set dates
|
||||||
|
viewModel.hasSetDates = true
|
||||||
|
XCTAssertTrue(viewModel.isRegionsStepVisible)
|
||||||
|
|
||||||
|
// Step 4: Select regions
|
||||||
|
viewModel.selectedRegions = [.east]
|
||||||
|
XCTAssertTrue(viewModel.isRoutePreferenceStepVisible)
|
||||||
|
|
||||||
|
// Step 5: Set route preference
|
||||||
|
viewModel.hasSetRoutePreference = true
|
||||||
|
XCTAssertTrue(viewModel.isRepeatCitiesStepVisible)
|
||||||
|
|
||||||
|
// Step 6: Set repeat cities preference
|
||||||
|
viewModel.hasSetRepeatCities = true
|
||||||
|
XCTAssertTrue(viewModel.isMustStopsStepVisible)
|
||||||
|
XCTAssertTrue(viewModel.isReviewStepVisible)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_regionSelection_revealsRoutePreference() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
viewModel.selectedSports = [.nba]
|
||||||
|
viewModel.hasSetDates = true
|
||||||
|
|
||||||
|
XCTAssertFalse(viewModel.isRoutePreferenceStepVisible)
|
||||||
|
|
||||||
|
viewModel.selectedRegions = [.central, .west]
|
||||||
|
|
||||||
|
XCTAssertTrue(viewModel.isRoutePreferenceStepVisible)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_routePreference_revealsRepeatCities() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
viewModel.selectedSports = [.mlb]
|
||||||
|
viewModel.hasSetDates = true
|
||||||
|
viewModel.selectedRegions = [.east]
|
||||||
|
|
||||||
|
XCTAssertFalse(viewModel.isRepeatCitiesStepVisible)
|
||||||
|
|
||||||
|
viewModel.hasSetRoutePreference = true
|
||||||
|
|
||||||
|
XCTAssertTrue(viewModel.isRepeatCitiesStepVisible)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_repeatCities_revealsMustStopsAndReview() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
viewModel.selectedSports = [.mlb]
|
||||||
|
viewModel.hasSetDates = true
|
||||||
|
viewModel.selectedRegions = [.east]
|
||||||
|
viewModel.hasSetRoutePreference = true
|
||||||
|
|
||||||
|
XCTAssertFalse(viewModel.isMustStopsStepVisible)
|
||||||
|
XCTAssertFalse(viewModel.isReviewStepVisible)
|
||||||
|
|
||||||
|
viewModel.hasSetRepeatCities = true
|
||||||
|
|
||||||
|
XCTAssertTrue(viewModel.isMustStopsStepVisible)
|
||||||
|
XCTAssertTrue(viewModel.isReviewStepVisible)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Reset Behavior Tests
|
||||||
|
|
||||||
|
func test_changingPlanningMode_resetsAllDownstreamState() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
|
||||||
|
// Set up full wizard state
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
viewModel.selectedSports = [.mlb, .nba]
|
||||||
|
viewModel.hasSetDates = true
|
||||||
|
viewModel.selectedRegions = [.east, .central]
|
||||||
|
viewModel.hasSetRoutePreference = true
|
||||||
|
viewModel.hasSetRepeatCities = true
|
||||||
|
viewModel.mustStopLocations = [LocationInput(name: "Test", coordinates: nil)]
|
||||||
|
|
||||||
|
// Change planning mode
|
||||||
|
viewModel.planningMode = .locations
|
||||||
|
|
||||||
|
// Verify all downstream state is reset
|
||||||
|
XCTAssertTrue(viewModel.selectedSports.isEmpty)
|
||||||
|
XCTAssertFalse(viewModel.hasSetDates)
|
||||||
|
XCTAssertTrue(viewModel.selectedRegions.isEmpty)
|
||||||
|
XCTAssertFalse(viewModel.hasSetRoutePreference)
|
||||||
|
XCTAssertFalse(viewModel.hasSetRepeatCities)
|
||||||
|
XCTAssertTrue(viewModel.mustStopLocations.isEmpty)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_settingSamePlanningMode_doesNotResetState() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
viewModel.selectedSports = [.mlb]
|
||||||
|
viewModel.hasSetDates = true
|
||||||
|
|
||||||
|
// Re-set the same mode
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
|
||||||
|
// State should NOT be reset
|
||||||
|
XCTAssertEqual(viewModel.selectedSports, [.mlb])
|
||||||
|
XCTAssertTrue(viewModel.hasSetDates)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Edge Cases
|
||||||
|
|
||||||
|
func test_emptyRegionSelection_hidesRoutePreference() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
viewModel.selectedSports = [.mlb]
|
||||||
|
viewModel.hasSetDates = true
|
||||||
|
viewModel.selectedRegions = [.west]
|
||||||
|
XCTAssertTrue(viewModel.isRoutePreferenceStepVisible)
|
||||||
|
|
||||||
|
viewModel.selectedRegions = []
|
||||||
|
|
||||||
|
XCTAssertFalse(viewModel.isRoutePreferenceStepVisible)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_multipleSports_canBeSelected() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
|
||||||
|
viewModel.selectedSports = [.mlb, .nba, .nhl]
|
||||||
|
|
||||||
|
XCTAssertEqual(viewModel.selectedSports.count, 3)
|
||||||
|
XCTAssertTrue(viewModel.isDatesStepVisible)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_multipleRegions_canBeSelected() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
viewModel.selectedSports = [.mlb]
|
||||||
|
viewModel.hasSetDates = true
|
||||||
|
|
||||||
|
viewModel.selectedRegions = [.east, .central, .west]
|
||||||
|
|
||||||
|
XCTAssertEqual(viewModel.selectedRegions.count, 3)
|
||||||
|
XCTAssertTrue(viewModel.isRoutePreferenceStepVisible)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Reveal State Bitmask Tests
|
||||||
|
|
||||||
|
func test_revealState_initialValue() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
|
||||||
|
XCTAssertEqual(viewModel.revealState, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_revealState_incrementsWithProgress() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
XCTAssertEqual(viewModel.revealState, 1) // Sports visible
|
||||||
|
|
||||||
|
viewModel.selectedSports = [.mlb]
|
||||||
|
XCTAssertEqual(viewModel.revealState, 3) // Sports + Dates
|
||||||
|
|
||||||
|
viewModel.hasSetDates = true
|
||||||
|
XCTAssertEqual(viewModel.revealState, 7) // Sports + Dates + Regions
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_revealState_fullFlow() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
viewModel.planningMode = .dateRange
|
||||||
|
viewModel.selectedSports = [.mlb]
|
||||||
|
viewModel.hasSetDates = true
|
||||||
|
viewModel.selectedRegions = [.east]
|
||||||
|
viewModel.hasSetRoutePreference = true
|
||||||
|
viewModel.hasSetRepeatCities = true
|
||||||
|
|
||||||
|
// 1 + 2 + 4 + 8 + 16 + 32 + 64 = 127
|
||||||
|
XCTAssertEqual(viewModel.revealState, 127)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Sport Availability Tests
|
||||||
|
|
||||||
|
func test_canSelectSport_defaultsToTrue() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
|
||||||
|
XCTAssertTrue(viewModel.canSelectSport(.mlb))
|
||||||
|
XCTAssertTrue(viewModel.canSelectSport(.nba))
|
||||||
|
XCTAssertTrue(viewModel.canSelectSport(.nhl))
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_canSelectSport_respectsAvailability() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
viewModel.sportAvailability = [.mlb: true, .nba: false, .nhl: true]
|
||||||
|
|
||||||
|
XCTAssertTrue(viewModel.canSelectSport(.mlb))
|
||||||
|
XCTAssertFalse(viewModel.canSelectSport(.nba))
|
||||||
|
XCTAssertTrue(viewModel.canSelectSport(.nhl))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Planning State Tests
|
||||||
|
|
||||||
|
func test_isPlanning_defaultsToFalse() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
|
||||||
|
XCTAssertFalse(viewModel.isPlanning)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_mustStopLocations_canBeAdded() {
|
||||||
|
let viewModel = TripWizardViewModel()
|
||||||
|
let location = LocationInput(name: "Chicago, IL", coordinates: nil)
|
||||||
|
|
||||||
|
viewModel.mustStopLocations.append(location)
|
||||||
|
|
||||||
|
XCTAssertEqual(viewModel.mustStopLocations.count, 1)
|
||||||
|
XCTAssertEqual(viewModel.mustStopLocations.first?.name, "Chicago, IL")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user