fix: preserve LocationSearchSheet coordinates in By Route mode

The resolveLocations() function was overwriting valid LocationInput
objects (with coordinates) from LocationSearchSheet. Now it only
resolves locations that don't already have coordinates.

Added debug logging to trace scenario selection.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-11 18:59:44 -06:00
parent 1967eecd52
commit 3f80a16201
2 changed files with 31 additions and 2 deletions

View File

@@ -280,16 +280,24 @@ final class TripCreationViewModel {
func resolveLocations() async {
do {
if !startLocationText.isEmpty {
// Only resolve if we don't already have a location with coordinates
// (LocationSearchSheet already provides full LocationInput with coordinates)
if !startLocationText.isEmpty && startLocation?.coordinate == nil {
print("🔍 resolveLocations: Resolving startLocation from text '\(startLocationText)'")
startLocation = try await locationService.resolveLocation(
LocationInput(name: startLocationText, address: startLocationText)
)
} else if startLocation?.coordinate != nil {
print("🔍 resolveLocations: startLocation already has coordinates, skipping resolve")
}
if !endLocationText.isEmpty {
if !endLocationText.isEmpty && endLocation?.coordinate == nil {
print("🔍 resolveLocations: Resolving endLocation from text '\(endLocationText)'")
endLocation = try await locationService.resolveLocation(
LocationInput(name: endLocationText, address: endLocationText)
)
} else if endLocation?.coordinate != nil {
print("🔍 resolveLocations: endLocation already has coordinates, skipping resolve")
}
} catch {
viewState = .error("Failed to resolve locations: \(error.localizedDescription)")
@@ -337,10 +345,21 @@ final class TripCreationViewModel {
case .locations:
// Resolve provided locations
print("🔍 ViewModel.planTrip: .locations mode")
print(" - startLocationText: '\(startLocationText)'")
print(" - endLocationText: '\(endLocationText)'")
print(" - startLocation BEFORE resolve: \(startLocation?.name ?? "nil")")
print(" - endLocation BEFORE resolve: \(endLocation?.name ?? "nil")")
await resolveLocations()
resolvedStartLocation = startLocation
resolvedEndLocation = endLocation
print(" - startLocation AFTER resolve: \(startLocation?.name ?? "nil")")
print(" - endLocation AFTER resolve: \(endLocation?.name ?? "nil")")
print(" - resolvedStartLocation: \(resolvedStartLocation?.name ?? "nil")")
print(" - resolvedEndLocation: \(resolvedEndLocation?.name ?? "nil")")
guard resolvedStartLocation != nil, resolvedEndLocation != nil else {
viewState = .error("Could not resolve start or end location")
return

View File

@@ -22,22 +22,32 @@ enum ScenarioPlannerFactory {
/// Creates the appropriate planner based on the request inputs
static func planner(for request: PlanningRequest) -> ScenarioPlanner {
print("🔍 ScenarioPlannerFactory: Selecting planner...")
print(" - followTeamId: \(request.preferences.followTeamId?.uuidString ?? "nil")")
print(" - selectedGames.count: \(request.selectedGames.count)")
print(" - startLocation: \(request.startLocation?.name ?? "nil")")
print(" - endLocation: \(request.endLocation?.name ?? "nil")")
// Scenario D: User wants to follow a specific team
if request.preferences.followTeamId != nil {
print("🔍 ScenarioPlannerFactory: → ScenarioDPlanner (follow team)")
return ScenarioDPlanner()
}
// Scenario B: User selected specific games
if !request.selectedGames.isEmpty {
print("🔍 ScenarioPlannerFactory: → ScenarioBPlanner (selected games)")
return ScenarioBPlanner()
}
// Scenario C: User specified start and end locations
if request.startLocation != nil && request.endLocation != nil {
print("🔍 ScenarioPlannerFactory: → ScenarioCPlanner (start/end locations)")
return ScenarioCPlanner()
}
// Scenario A: Date range only (default)
print("🔍 ScenarioPlannerFactory: → ScenarioAPlanner (default/date range)")
return ScenarioAPlanner()
}