-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(child-stop-details.js): Fixed flow errors
- Loading branch information
1 parent
57cb055
commit 062f164
Showing
5 changed files
with
150 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, { Component } from 'react' | ||
|
||
import { stopTimeComparator } from '../../util/viewer' | ||
|
||
import StopTimeCell from './stop-time-cell' | ||
|
||
/** | ||
* Shows the next arrival for a pattern within the related stops view. | ||
*/ | ||
export default class NextArrivalForPattern extends Component { | ||
render () { | ||
const { | ||
homeTimezone, | ||
route, | ||
stopTimes, | ||
stopViewerArriving, | ||
stopViewerConfig, | ||
timeFormat | ||
} = this.props | ||
|
||
// sort stop times by next departure | ||
let sortedStopTimes = [] | ||
const hasStopTimes = stopTimes && stopTimes.length > 0 | ||
if (hasStopTimes) { | ||
sortedStopTimes = stopTimes | ||
.concat() | ||
.sort(stopTimeComparator) | ||
// We request only x departures per pattern, but the patterns are merged | ||
// according to shared headsigns, so we need to slice the stop times | ||
// here as well to ensure only x times are shown per route/headsign combo. | ||
// This is applied after the sort, so we're keeping the soonest departures. | ||
.slice(0, stopViewerConfig.numberOfDepartures) | ||
} else { | ||
// Do not render pattern row if it has no stop times. | ||
return null | ||
} | ||
|
||
const routeName = route.shortName ? route.shortName : route.longName | ||
return ( | ||
<div style={{ display: 'flex', width: '100%', alignItems: 'center' }}> | ||
{/* route name */} | ||
<div style={{ display: 'flex', marginRight: '20px', alignItems: 'center' }}> | ||
<span style={{ | ||
border: '1px solid', | ||
borderRadius: '50%', | ||
padding: '4px', | ||
fontSize: '13px', | ||
width: '24px', | ||
height: '24px', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
position: 'relative', | ||
letterSpacing: '-1.5px', | ||
textAlign: 'center', | ||
marginRight: '5px' | ||
}}>{routeName}</span> To {route.longName} | ||
</div> | ||
{/* next departure preview */} | ||
{hasStopTimes && ( | ||
<div> | ||
<StopTimeCell | ||
homeTimezone={homeTimezone} | ||
soonText={stopViewerArriving} | ||
stopTime={sortedStopTimes[0]} | ||
timeFormat={timeFormat} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
} |
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