diff --git a/SportsTime/Features/Home/Views/HomeView.swift b/SportsTime/Features/Home/Views/HomeView.swift index 1942858..1935b80 100644 --- a/SportsTime/Features/Home/Views/HomeView.swift +++ b/SportsTime/Features/Home/Views/HomeView.swift @@ -12,6 +12,7 @@ struct HomeView: View { @Query(sort: \SavedTrip.updatedAt, order: .reverse) private var savedTrips: [SavedTrip] @State private var showNewTrip = false + @State private var selectedSport: Sport? @State private var selectedTab = 0 var body: some View { @@ -88,7 +89,12 @@ struct HomeView: View { } .tint(Theme.warmOrange) .sheet(isPresented: $showNewTrip) { - TripCreationView() + TripCreationView(initialSport: selectedSport) + } + .onChange(of: showNewTrip) { _, isShowing in + if !isShowing { + selectedSport = nil + } } } @@ -146,6 +152,7 @@ struct HomeView: View { HStack(spacing: Theme.Spacing.sm) { ForEach(Sport.supported) { sport in QuickSportButton(sport: sport) { + selectedSport = sport showNewTrip = true } } diff --git a/SportsTime/Features/Trip/Views/TripCreationView.swift b/SportsTime/Features/Trip/Views/TripCreationView.swift index 2b9c0bd..61c635d 100644 --- a/SportsTime/Features/Trip/Views/TripCreationView.swift +++ b/SportsTime/Features/Trip/Views/TripCreationView.swift @@ -9,7 +9,13 @@ struct TripCreationView: View { @Environment(\.dismiss) private var dismiss @Environment(\.colorScheme) private var colorScheme + let initialSport: Sport? + @State private var viewModel = TripCreationViewModel() + + init(initialSport: Sport? = nil) { + self.initialSport = initialSport + } @State private var showGamePicker = false @State private var showCityInput = false @State private var cityInputType: CityInputType = .mustStop @@ -161,6 +167,11 @@ struct TripCreationView: View { .task { await viewModel.loadScheduleData() } + .onAppear { + if let sport = initialSport { + viewModel.selectedSports = [sport] + } + } } }