fix: restrict By Route wizard to stadium cities and filter sports by selected cities
LocationSearchSheet now shows only stadium cities (with sport badges) when selecting start/end locations, preventing users from picking cities with no stadiums. TripWizardViewModel filters available sports to the union of sports at the selected cities, and clears invalid selections when locations change. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -161,8 +161,48 @@ final class TripWizardViewModel {
|
||||
|
||||
// MARK: - Sport Availability
|
||||
|
||||
/// Sports available at the selected start and/or end cities (union of both)
|
||||
var sportsAtSelectedCities: Set<Sport> {
|
||||
let stadiums = AppDataProvider.shared.stadiums
|
||||
var sports: Set<Sport> = []
|
||||
|
||||
if let startCity = startLocation?.name {
|
||||
let normalized = startCity.split(separator: ",").first?
|
||||
.trimmingCharacters(in: .whitespaces).lowercased() ?? ""
|
||||
for stadium in stadiums where stadium.city.lowercased() == normalized {
|
||||
sports.insert(stadium.sport)
|
||||
}
|
||||
}
|
||||
if let endCity = endLocation?.name {
|
||||
let normalized = endCity.split(separator: ",").first?
|
||||
.trimmingCharacters(in: .whitespaces).lowercased() ?? ""
|
||||
for stadium in stadiums where stadium.city.lowercased() == normalized {
|
||||
sports.insert(stadium.sport)
|
||||
}
|
||||
}
|
||||
return sports
|
||||
}
|
||||
|
||||
func canSelectSport(_ sport: Sport) -> Bool {
|
||||
sportAvailability[sport] ?? true // Default to available if not checked
|
||||
// Existing date-range availability check
|
||||
let dateAvailable = sportAvailability[sport] ?? true
|
||||
|
||||
// For locations mode, also check if sport has stadiums at selected cities
|
||||
if planningMode == .locations,
|
||||
startLocation != nil || endLocation != nil {
|
||||
let cityAvailable = sportsAtSelectedCities.contains(sport)
|
||||
return dateAvailable && cityAvailable
|
||||
}
|
||||
|
||||
return dateAvailable
|
||||
}
|
||||
|
||||
/// Removes selected sports that are no longer available at the chosen cities
|
||||
func validateSportsForLocations() {
|
||||
guard planningMode == .locations else { return }
|
||||
let available = sportsAtSelectedCities
|
||||
guard !available.isEmpty else { return }
|
||||
selectedSports = selectedSports.filter { available.contains($0) }
|
||||
}
|
||||
|
||||
func fetchSportAvailability() async {
|
||||
|
||||
Reference in New Issue
Block a user