fix: use LocationSearchSheet for Start/End Location fields

Replaces inline text fields with buttons that open LocationSearchSheet,
matching the must-stop location picker UI for consistency.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-11 18:50:19 -06:00
parent 81095a8170
commit 1967eecd52

View File

@@ -39,6 +39,8 @@ struct TripCreationView: View {
case mustStop case mustStop
case preferred case preferred
case homeLocation case homeLocation
case startLocation
case endLocation
} }
var body: some View { var body: some View {
@@ -122,9 +124,12 @@ struct TripCreationView: View {
viewModel.addMustStopLocation(location) viewModel.addMustStopLocation(location)
case .preferred: case .preferred:
viewModel.addPreferredCity(location.name) viewModel.addPreferredCity(location.name)
case .homeLocation: case .homeLocation, .startLocation:
viewModel.startLocationText = location.name viewModel.startLocationText = location.name
viewModel.startLocation = location viewModel.startLocation = location
case .endLocation:
viewModel.endLocationText = location.name
viewModel.endLocation = location
} }
} }
} }
@@ -240,71 +245,68 @@ struct TripCreationView: View {
private var locationSection: some View { private var locationSection: some View {
ThemedSection(title: "Locations") { ThemedSection(title: "Locations") {
// Start Location with suggestions // Start Location - opens search sheet
VStack(alignment: .leading, spacing: 0) { locationButton(
ThemedTextField(
label: "Start Location", label: "Start Location",
placeholder: "Where are you starting from?", icon: "location.circle.fill",
text: $viewModel.startLocationText, location: viewModel.startLocation,
icon: "location.circle.fill" placeholder: "Where are you starting from?"
) ) {
.onChange(of: viewModel.startLocationText) { _, newValue in cityInputType = .startLocation
searchLocation(query: newValue, isStart: true) showCityInput = true
} }
// Suggestions for start location // End Location - opens search sheet
if !startLocationSuggestions.isEmpty { locationButton(
locationSuggestionsList(
suggestions: startLocationSuggestions,
isLoading: isSearchingStart
) { result in
viewModel.startLocationText = result.name
viewModel.startLocation = result.toLocationInput()
startLocationSuggestions = []
}
} else if isSearchingStart {
HStack {
ThemedSpinnerCompact(size: 14)
Text("Searching...")
.font(.subheadline)
.foregroundStyle(Theme.textMuted(colorScheme))
}
.padding(.top, Theme.Spacing.xs)
}
}
// End Location with suggestions
VStack(alignment: .leading, spacing: 0) {
ThemedTextField(
label: "End Location", label: "End Location",
placeholder: "Where do you want to end up?", icon: "mappin.circle.fill",
text: $viewModel.endLocationText, location: viewModel.endLocation,
icon: "mappin.circle.fill" placeholder: "Where do you want to end up?"
) ) {
.onChange(of: viewModel.endLocationText) { _, newValue in cityInputType = .endLocation
searchLocation(query: newValue, isStart: false) showCityInput = true
}
}
} }
// Suggestions for end location private func locationButton(
if !endLocationSuggestions.isEmpty { label: String,
locationSuggestionsList( icon: String,
suggestions: endLocationSuggestions, location: LocationInput?,
isLoading: isSearchingEnd placeholder: String,
) { result in action: @escaping () -> Void
viewModel.endLocationText = result.name ) -> some View {
viewModel.endLocation = result.toLocationInput() VStack(alignment: .leading, spacing: Theme.Spacing.xs) {
endLocationSuggestions = [] Text(label)
}
} else if isSearchingEnd {
HStack {
ThemedSpinnerCompact(size: 14)
Text("Searching...")
.font(.subheadline) .font(.subheadline)
.fontWeight(.medium)
.foregroundStyle(Theme.warmOrange)
Button(action: action) {
HStack(spacing: Theme.Spacing.md) {
Image(systemName: icon)
.foregroundStyle(Theme.warmOrange)
.frame(width: 24)
if let location = location {
Text(location.name)
.foregroundStyle(Theme.textPrimary(colorScheme))
} else {
Text(placeholder)
.foregroundStyle(Theme.textMuted(colorScheme)) .foregroundStyle(Theme.textMuted(colorScheme))
} }
.padding(.top, Theme.Spacing.xs)
Spacer()
Image(systemName: "chevron.right")
.font(.caption)
.foregroundStyle(Theme.textMuted(colorScheme))
} }
.padding(Theme.Spacing.md)
.background(Theme.cardBackgroundElevated(colorScheme))
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
} }
.buttonStyle(.plain)
} }
} }