fix: resolve 4 UI/planning bugs from issue tracker

- Lock all maps to North America (no pan/zoom) in ProgressMapView and TripDetailView
- Sort saved trips by most cities (stops count)
- Filter cross-country trips to top 2 by stops on home screen
- Use LocationSearchSheet for Follow Team home location (consistent with must-stop)
- Initialize DateRangePicker to show selected dates on appear

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-11 18:46:40 -06:00
parent c2f52aaccc
commit 81095a8170
9 changed files with 418 additions and 88 deletions

View File

@@ -36,7 +36,33 @@ final class TripCreationViewModel {
// MARK: - Planning Mode
var planningMode: PlanningMode = .dateRange
var planningMode: PlanningMode = .dateRange {
didSet {
// Reset state when mode changes to ensure clean UI transitions
if oldValue != planningMode {
viewState = .editing
// Clear mode-specific selections
switch planningMode {
case .dateRange, .gameFirst:
// Clear locations for date-based modes
startLocationText = ""
endLocationText = ""
startLocation = nil
endLocation = nil
case .locations:
// Keep locations (user needs to enter them)
break
case .followTeam:
// Clear locations and must-see games for follow team mode
startLocationText = ""
endLocationText = ""
startLocation = nil
endLocation = nil
mustSeeGameIds.removeAll()
}
}
}
}
// MARK: - Form Fields
@@ -61,7 +87,9 @@ final class TripCreationViewModel {
var startDate: Date = Date() {
didSet {
// Clear cached games when start date changes
if !Calendar.current.isDate(startDate, inSameDayAs: oldValue) {
// BUT: In gameFirst mode, games are the source of truth for dates,
// so don't clear them (fixes "date range required" error)
if !Calendar.current.isDate(startDate, inSameDayAs: oldValue) && planningMode != .gameFirst {
availableGames = []
games = []
}
@@ -70,7 +98,9 @@ final class TripCreationViewModel {
var endDate: Date = Date().addingTimeInterval(86400 * 7) {
didSet {
// Clear cached games when end date changes
if !Calendar.current.isDate(endDate, inSameDayAs: oldValue) {
// BUT: In gameFirst mode, games are the source of truth for dates,
// so don't clear them (fixes "date range required" error)
if !Calendar.current.isDate(endDate, inSameDayAs: oldValue) && planningMode != .gameFirst {
availableGames = []
games = []
}
@@ -414,32 +444,8 @@ final class TripCreationViewModel {
}
func switchPlanningMode(_ mode: PlanningMode) {
// Just set the mode - didSet observer handles state reset
planningMode = mode
// Clear mode-specific selections when switching
switch mode {
case .dateRange:
startLocationText = ""
endLocationText = ""
startLocation = nil
endLocation = nil
case .gameFirst:
// Keep games, clear locations
startLocationText = ""
endLocationText = ""
startLocation = nil
endLocation = nil
case .locations:
// Keep locations, optionally keep selected games
break
case .followTeam:
// Clear non-follow-team selections
startLocationText = ""
endLocationText = ""
startLocation = nil
endLocation = nil
mustSeeGameIds.removeAll()
}
}
/// Load games for browsing in game-first mode

View File

@@ -38,6 +38,7 @@ struct TripCreationView: View {
enum CityInputType {
case mustStop
case preferred
case homeLocation
}
var body: some View {
@@ -121,6 +122,9 @@ struct TripCreationView: View {
viewModel.addMustStopLocation(location)
case .preferred:
viewModel.addPreferredCity(location.name)
case .homeLocation:
viewModel.startLocationText = location.name
viewModel.startLocation = location
}
}
}
@@ -595,38 +599,50 @@ struct TripCreationView: View {
)
if viewModel.useHomeLocation {
// Show home location input with suggestions
VStack(alignment: .leading, spacing: 0) {
ThemedTextField(
label: "Home Location",
placeholder: "Enter your city",
text: $viewModel.startLocationText,
icon: "house.fill"
)
.onChange(of: viewModel.startLocationText) { _, newValue in
searchLocation(query: newValue, isStart: true)
}
// Show button to open location search sheet (same as must-stop)
Button {
cityInputType = .homeLocation
showCityInput = true
} label: {
HStack(spacing: Theme.Spacing.md) {
ZStack {
Circle()
.fill(Theme.warmOrange.opacity(0.15))
.frame(width: 40, height: 40)
Image(systemName: "house.fill")
.foregroundStyle(Theme.warmOrange)
}
// Suggestions for home location
if !startLocationSuggestions.isEmpty {
locationSuggestionsList(
suggestions: startLocationSuggestions,
isLoading: isSearchingStart
) { result in
viewModel.startLocationText = result.name
viewModel.startLocation = result.toLocationInput()
startLocationSuggestions = []
VStack(alignment: .leading, spacing: 2) {
if let location = viewModel.startLocation {
Text(location.name)
.font(.body)
.foregroundStyle(Theme.textPrimary(colorScheme))
if let address = location.address, !address.isEmpty {
Text(address)
.font(.caption)
.foregroundStyle(Theme.textSecondary(colorScheme))
}
} else {
Text("Choose home location")
.font(.body)
.foregroundStyle(Theme.textPrimary(colorScheme))
Text("Tap to search cities")
.font(.caption)
.foregroundStyle(Theme.textMuted(colorScheme))
}
}
} else if isSearchingStart {
HStack {
ThemedSpinnerCompact(size: 14)
Text("Searching...")
.font(.subheadline)
.foregroundStyle(Theme.textMuted(colorScheme))
}
.padding(.top, Theme.Spacing.xs)
Spacer()
Image(systemName: "chevron.right")
.foregroundStyle(Theme.textMuted(colorScheme))
}
.padding(Theme.Spacing.md)
.background(Theme.cardBackgroundElevated(colorScheme))
.clipShape(RoundedRectangle(cornerRadius: Theme.CornerRadius.medium))
}
.buttonStyle(.plain)
} else {
Text("Trip will start at first game and end at last game (fly-in/fly-out)")
.font(.caption)
@@ -2099,6 +2115,14 @@ struct DateRangePicker: View {
// Trip duration
tripDurationBadge
}
.onAppear {
// Initialize displayed month to show the start date's month
displayedMonth = calendar.startOfDay(for: startDate)
// If dates are already selected (endDate > startDate), show complete state
if endDate > startDate {
selectionState = .complete
}
}
}
private var selectedRangeSummary: some View {

View File

@@ -157,7 +157,7 @@ struct TripDetailView: View {
private var heroMapSection: some View {
ZStack(alignment: .bottom) {
Map(position: $mapCameraPosition) {
Map(position: $mapCameraPosition, interactionModes: []) {
ForEach(stopCoordinates.indices, id: \.self) { index in
let stop = stopCoordinates[index]
Annotation(stop.name, coordinate: stop.coordinate) {