diff --git a/Flights/Views/HistoryRouteMapView.swift b/Flights/Views/HistoryRouteMapView.swift index ff0fda5..8b0aefa 100644 --- a/Flights/Views/HistoryRouteMapView.swift +++ b/Flights/Views/HistoryRouteMapView.swift @@ -20,13 +20,24 @@ import CoreLocation /// 5. Bottom drawer is a real swipe-up sheet with detents — peek /// shows the count + replay; expanded shows filter chips. struct HistoryRouteMapView: View { - let flights: [LoggedFlight] // filtered - let allFlights: [LoggedFlight] // unfiltered (kept for parent-API compat) + /// The user's full unfiltered log. The map filters this set + /// internally by `filters` so changes from the in-map filter sheet + /// reliably re-scope the animation, even if the parent's + /// .sheet content closure doesn't propagate a new pre-filtered + /// array to us in time. + let allFlights: [LoggedFlight] let database: AirportDatabase let openSky: OpenSkyClient let store: FlightHistoryStore @Binding var filters: HistoryFilters + /// Locally-derived "what to draw" set. Recomputed on every body + /// pass; cheap because it's a single array filter on ~hundreds of + /// items at most. + private var flights: [LoggedFlight] { + allFlights.filter { filters.matches($0) } + } + @State private var position: MapCameraPosition = .automatic @State private var progress: Double = 0 @State private var animationKey: Int = 0 diff --git a/Flights/Views/HistoryView.swift b/Flights/Views/HistoryView.swift index 8366613..ea9602b 100644 --- a/Flights/Views/HistoryView.swift +++ b/Flights/Views/HistoryView.swift @@ -102,7 +102,13 @@ struct HistoryView: View { } Section("Explore") { Button { showingPassport = true } label: { Label("Passport", systemImage: "book.closed") } - Button { showingMap = true } label: { Label("Route map", systemImage: "map.fill") } + Button { + // Carry the year-strip scope into the map's + // filter binding so the map opens showing + // the same year the user was browsing. + if let y = selectedYear { filters.years = [y] } + showingMap = true + } label: { Label("Route map", systemImage: "map.fill") } Button { showingAircraftStats = true } label: { Label("Aircraft stats", systemImage: "airplane.circle") } Button { showingYearInReview = true } label: { Label("Year in Review", systemImage: "sparkles") } } @@ -123,7 +129,6 @@ struct HistoryView: View { .sheet(isPresented: $showingMap) { NavigationStack { HistoryRouteMapView( - flights: scoped, allFlights: flights, database: database, openSky: openSky, @@ -285,7 +290,10 @@ struct HistoryView: View { @ViewBuilder private var quickLinks: some View { HStack(spacing: 10) { - quickLink(title: "Map", icon: "map.fill") { showingMap = true } + quickLink(title: "Map", icon: "map.fill") { + if let y = selectedYear { filters.years = [y] } + showingMap = true + } quickLink(title: "Aircraft", icon: "airplane.circle.fill") { showingAircraftStats = true } quickLink(title: "Year", icon: "sparkles") { showingYearInReview = true } }