-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show filtered departures in stop details (#124)
* implement filter * rethink binding one more time * add tests * rename NearbyStopRoutePatternView to HeadsignRowView * also move UpcomingTripView into ComponentViews * rearrange splitPerTrip * filter to route in FilteredRouteView constructor * make stack deeper for lastStopDetailsFilter test
- Loading branch information
1 parent
65c27e1
commit f7ab56e
Showing
18 changed files
with
477 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
iosApp/iosApp/Pages/StopDetails/StopDetailsFilteredRouteView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// StopDetailsFilteredRouteView.swift | ||
// iosApp | ||
// | ||
// Created by Horn, Melody on 2024-04-05. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import shared | ||
import SwiftUI | ||
|
||
struct StopDetailsFilteredRouteView: View { | ||
let patternsByStop: PatternsByStop | ||
let now: Instant | ||
@Binding var filter: StopDetailsFilter? | ||
|
||
struct RowData { | ||
let tripId: String | ||
let headsign: String | ||
let formatted: PatternsByHeadsign.Format | ||
|
||
init?(trip: UpcomingTrip, route: Route, expectedDirection: Int32?, now: Instant) { | ||
if trip.trip.directionId != expectedDirection { | ||
return nil | ||
} | ||
|
||
tripId = trip.trip.id | ||
headsign = trip.trip.headsign | ||
formatted = PatternsByHeadsign( | ||
route: route, headsign: headsign, patterns: [], upcomingTrips: [trip], alertsHere: nil | ||
).format(now: now) | ||
|
||
if !(formatted is PatternsByHeadsign.FormatSome) { | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
let rows: [RowData] | ||
|
||
init(departures: StopDetailsDepartures, now: Instant, filter filterBinding: Binding<StopDetailsFilter?>) { | ||
_filter = filterBinding | ||
let filter = filterBinding.wrappedValue | ||
let patternsByStop = departures.routes.first(where: { $0.route.id == filter?.routeId })! | ||
self.patternsByStop = patternsByStop | ||
self.now = now | ||
|
||
let expectedDirection: Int32? = filter?.directionId | ||
rows = patternsByStop.allUpcomingTrips().compactMap { | ||
RowData(trip: $0, route: patternsByStop.route, expectedDirection: expectedDirection, now: now) | ||
} | ||
} | ||
|
||
var body: some View { | ||
Button(action: { filter = nil }, label: { Text("Clear Filter") }) | ||
List { | ||
RoutePillSection(route: patternsByStop.route) { | ||
ForEach(rows, id: \.tripId) { row in | ||
HeadsignRowView(headsign: row.headsign, predictions: row.formatted) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.