@@ -13,7 +13,7 @@ import { setMainPanelContent, toggleAutoRefresh } from '../../actions/ui'
13
13
import { findStop , findStopTimesForStop } from '../../actions/api'
14
14
import { forgetStop , rememberStop , setLocation } from '../../actions/map'
15
15
import { routeComparator } from '../../util/itinerary'
16
- import { getShowUserSettings } from '../../util/state'
16
+ import { getShowUserSettings , getStopViewerConfig } from '../../util/state'
17
17
import { formatDuration , formatStopTime , getTimeFormat } from '../../util/time'
18
18
19
19
class StopViewer extends Component {
@@ -116,6 +116,7 @@ class StopViewer extends Component {
116
116
showUserSettings,
117
117
stopData,
118
118
stopViewerArriving,
119
+ stopViewerConfig,
119
120
timeFormat
120
121
} = this . props
121
122
const { spin } = this . state
@@ -237,6 +238,7 @@ class StopViewer extends Component {
237
238
pattern = { patternTimes . pattern }
238
239
route = { patternTimes . route }
239
240
stopTimes = { patternTimes . times }
241
+ stopViewerConfig = { stopViewerConfig }
240
242
key = { patternTimes . id }
241
243
stopViewerArriving = { stopViewerArriving }
242
244
homeTimezone = { homeTimezone }
@@ -282,23 +284,28 @@ class PatternRow extends Component {
282
284
stopTimes,
283
285
homeTimezone,
284
286
stopViewerArriving,
287
+ stopViewerConfig,
285
288
timeFormat
286
289
} = this . props
287
290
// sort stop times by next departure
288
- let sortedStopTimes = null
289
- if ( stopTimes ) {
290
- sortedStopTimes = stopTimes . sort ( ( a , b ) => {
291
- const aTime = a . serviceDay + a . realtimeDeparture
292
- const bTime = b . serviceDay + b . realtimeDeparture
293
- return aTime - bTime
294
- } )
295
- // Cap the number of times shown for any Route at 5. TODO: make configurable
296
- if ( sortedStopTimes . length > 0 ) sortedStopTimes = sortedStopTimes . slice ( 0 , 5 )
297
- // Do not show any patterns with no departures happening soon.
298
- const timeIsOverThreshold = sortedStopTimes [ 0 ] . realtimeDeparture - getHomeTime ( homeTimezone ) > ONE_HOUR_IN_SECONDS * 3
299
- if ( sortedStopTimes [ 0 ] && timeIsOverThreshold ) {
300
- return null
301
- }
291
+ let sortedStopTimes = [ ]
292
+ const hasStopTimes = stopTimes && stopTimes . length > 0
293
+ if ( hasStopTimes ) {
294
+ sortedStopTimes = stopTimes
295
+ . concat ( )
296
+ . sort ( ( a , b ) => {
297
+ const aTime = a . serviceDay + a . realtimeDeparture
298
+ const bTime = b . serviceDay + b . realtimeDeparture
299
+ return aTime - bTime
300
+ } )
301
+ // We request only x departures per pattern, but the patterns are merged
302
+ // according to shared headsigns, so we need to slice the stop times
303
+ // here as well to ensure only x times are shown per route/headsign combo.
304
+ // This is applied after the sort, so we're keeping the soonest departures.
305
+ . slice ( 0 , stopViewerConfig . numberOfDepartures )
306
+ } else {
307
+ // Do not include pattern row if it has no stop times.
308
+ return null
302
309
}
303
310
const routeName = route . shortName ? route . shortName : route . longName
304
311
@@ -314,7 +321,7 @@ class PatternRow extends Component {
314
321
</ div >
315
322
316
323
{ /* next departure preview */ }
317
- { stopTimes && stopTimes . length > 0 && (
324
+ { hasStopTimes && (
318
325
< div className = 'next-trip-preview' >
319
326
{ getFormattedStopTime ( sortedStopTimes [ 0 ] , homeTimezone , stopViewerArriving , timeFormat ) }
320
327
</ div >
@@ -343,7 +350,7 @@ class PatternRow extends Component {
343
350
</ div >
344
351
345
352
{ /* list of upcoming trips */ }
346
- { stopTimes && (
353
+ { hasStopTimes && (
347
354
sortedStopTimes . map ( ( stopTime , i ) => {
348
355
return (
349
356
< div
@@ -485,6 +492,7 @@ function getStatusLabel (delay) {
485
492
486
493
const mapStateToProps = ( state , ownProps ) => {
487
494
const showUserSettings = getShowUserSettings ( state . otp )
495
+ const stopViewerConfig = getStopViewerConfig ( state . otp )
488
496
return {
489
497
autoRefreshStopTimes : state . otp . user . autoRefreshStopTimes ,
490
498
favoriteStops : state . otp . user . favoriteStops ,
@@ -493,6 +501,7 @@ const mapStateToProps = (state, ownProps) => {
493
501
showUserSettings,
494
502
stopData : state . otp . transitIndex . stops [ state . otp . ui . viewedStop . stopId ] ,
495
503
stopViewerArriving : state . otp . config . language . stopViewerArriving ,
504
+ stopViewerConfig,
496
505
timeFormat : getTimeFormat ( state . otp . config )
497
506
}
498
507
}
0 commit comments