@@ -8,6 +8,7 @@ import * as apiActions from '../../../actions/api'
88import * as mapActions from '../../../actions/map'
99import * as uiActions from '../../../actions/ui'
1010import { AppReduxState } from '../../../util/state-types'
11+ import { getCurrentServiceWeek } from '../../../util/current-service-week'
1112import { SetLocationHandler , ZoomToPlaceHandler } from '../../util/types'
1213import Loading from '../../narrative/loading'
1314import MobileContainer from '../../mobile/container'
@@ -31,13 +32,19 @@ const AUTO_REFRESH_INTERVAL = 15000
3132// TODO: use lonlat package
3233type LatLonObj = { lat : number ; lon : number }
3334type CurrentPosition = { coords ?: { latitude : number ; longitude : number } }
35+ type ServiceWeek = { end : string ; start : string }
3436
3537type Props = {
3638 currentPosition ?: CurrentPosition
39+ currentServiceWeek ?: ServiceWeek
3740 defaultLatLon : LatLonObj | null
3841 displayedCoords ?: LatLonObj
3942 entityId ?: string
40- fetchNearby : ( latLon : LatLonObj , radius ?: number ) => void
43+ fetchNearby : (
44+ latLon : LatLonObj ,
45+ radius ?: number ,
46+ currentServiceWeek ?: ServiceWeek
47+ ) => void
4148 hideBackButton ?: boolean
4249 location : string
4350 mobile ?: boolean
@@ -102,6 +109,7 @@ function getNearbyCoordsFromUrlOrLocationOrMapCenter(
102109
103110function NearbyView ( {
104111 currentPosition,
112+ currentServiceWeek,
105113 defaultLatLon,
106114 displayedCoords,
107115 entityId,
@@ -175,10 +183,10 @@ function NearbyView({
175183 firstItemRef . current ?. scrollIntoView ( { behavior : 'smooth' } )
176184 }
177185 if ( finalNearbyCoords ) {
178- fetchNearby ( finalNearbyCoords , radius )
186+ fetchNearby ( finalNearbyCoords , radius , currentServiceWeek )
179187 setLoading ( true )
180188 const interval = setInterval ( ( ) => {
181- fetchNearby ( finalNearbyCoords , radius )
189+ fetchNearby ( finalNearbyCoords , radius , currentServiceWeek )
182190 setLoading ( true )
183191 } , AUTO_REFRESH_INTERVAL )
184192 return function cleanup ( ) {
@@ -204,6 +212,16 @@ function NearbyView({
204212 finalNearbyCoords ?. lat !== displayedCoords ?. lat ||
205213 finalNearbyCoords ?. lon !== displayedCoords ?. lon
206214
215+ // Build list of nearby routes for filtering within the stop card
216+ const nearbyRoutes = Array . from (
217+ new Set (
218+ nearby
219+ ?. map ( ( n : any ) =>
220+ n . place ?. stopRoutes ?. map ( ( sr : { gtfsId ?: string } ) => sr ?. gtfsId )
221+ )
222+ . flat ( Infinity )
223+ )
224+ )
207225 const nearbyItemList =
208226 nearby ?. map &&
209227 nearby ?. map ( ( n : any ) => (
@@ -223,7 +241,7 @@ function NearbyView({
223241 /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
224242 tabIndex = { 0 }
225243 >
226- { getNearbyItem ( { ...n . place , distance : n . distance } ) }
244+ { getNearbyItem ( { ...n . place , distance : n . distance , nearbyRoutes } ) }
227245 </ div >
228246 </ li >
229247 ) )
@@ -290,15 +308,22 @@ function NearbyView({
290308
291309const mapStateToProps = ( state : AppReduxState ) => {
292310 const { config, location, transitIndex, ui } = state . otp
293- const { map } = state . otp . config
311+ const { map, routeViewer } = config
294312 const { nearbyViewCoords } = ui
295313 const { nearby } = transitIndex
296314 const { entityId } = state . router . location . query
297315 const { currentPosition } = location
298316 const defaultLatLon =
299317 map ?. initLat && map ?. initLon ? { lat : map . initLat , lon : map . initLon } : null
318+
319+ const currentServiceWeek =
320+ routeViewer ?. onlyShowCurrentServiceWeek === true
321+ ? getCurrentServiceWeek ( )
322+ : undefined
323+
300324 return {
301325 currentPosition,
326+ currentServiceWeek,
302327 defaultLatLon,
303328 displayedCoords : nearby ?. coords ,
304329 entityId : entityId && decodeURIComponent ( entityId ) ,
0 commit comments