- }
>
)
}
diff --git a/lib/components/viewers/stop-schedule-table.js b/lib/components/viewers/stop-schedule-table.js
index 429a3cc70..601506293 100644
--- a/lib/components/viewers/stop-schedule-table.js
+++ b/lib/components/viewers/stop-schedule-table.js
@@ -1,3 +1,4 @@
+import moment from 'moment'
import React, { Component, createRef } from 'react'
import styled from 'styled-components'
@@ -43,16 +44,20 @@ const TimeCell = styled.td`
white-space: nowrap;
`
+/**
+ * Table showing scheduled departure times for the specified stop organized
+ * chronologically.
+ */
class StopScheduleTable extends Component {
- firstDepartureRef = createRef()
+ targetDepartureRef = createRef()
/*
* Scroll to the first stop time that is departing from now.
*/
_scrollToFirstDeparture = () => {
- const { current } = this.firstDepartureRef
+ const { current } = this.targetDepartureRef
if (current) {
- current.scrollIntoView()
+ current.scrollIntoView({ behavior: 'smooth', block: 'start' })
}
}
@@ -66,7 +71,7 @@ class StopScheduleTable extends Component {
}
render () {
- const { homeTimezone, stopData, timeFormat } = this.props
+ const { date, homeTimezone, stopData, timeFormat } = this.props
const stopTimesByPattern = getStopTimesByPattern(stopData)
// Merge stop times, so that we can sort them across all route patterns.
@@ -91,10 +96,11 @@ class StopScheduleTable extends Component {
})
mergedStopTimes = mergedStopTimes.sort(stopTimeComparator)
-
- // Find the next stop time that is departing. We will scroll to that stop time entry.
+ const today = moment().startOf('day').format('YYYY-MM-DD')
+ // Find the next stop time that is departing.
+ // We will scroll to that stop time entry (if showing schedules for today).
let firstDepartureFromNow
- if (mergedStopTimes.length) {
+ if (mergedStopTimes.length && date === today) {
// Search starting from the last stop time (largest seconds until departure) for this pattern.
const lastStopTime = mergedStopTimes[mergedStopTimes.length - 1]
@@ -121,12 +127,23 @@ class StopScheduleTable extends Component {
{mergedStopTimes.map((stopTime, index) => {
const { blockId, headsign, route } = stopTime
+ // Highlight if this row is the imminent departure.
+ const highlightRow = stopTime === firstDepartureFromNow
+ const className = highlightRow ? 'highlighted-item' : null
+ // FIXME: This is a bit of a hack to account for the sticky table
+ // header interfering with the scrollIntoView. If the next stop time
+ // is the imminent departure, we'll set the scrollTo to this row (the
+ // stop time prior), which effectively applies an offset for the
+ // scroll. If next row does not exist, default to this row.
+ const nextStopTime = mergedStopTimes[index + 1]
+ const scrollToRow = nextStopTime
+ ? nextStopTime === firstDepartureFromNow
+ : highlightRow
const routeName = route.shortName ? route.shortName : route.longName
// Add ref to scroll to the first stop time departing from now.
- const refProp = stopTime === firstDepartureFromNow ? this.firstDepartureRef : null
-
+ const refProp = scrollToRow ? this.targetDepartureRef : null
return (
-