Skip to content

Commit 57cb055

Browse files
committed
feat(child-stop-details.js): Created basic template with data from api ready to style - phase 1
#412
1 parent 5dde8db commit 57cb055

File tree

6 files changed

+82
-67
lines changed

6 files changed

+82
-67
lines changed

lib/actions/api.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,12 @@ export function findNearbyStops (params, parentStopId) {
795795
// retrieve routes for each stop
796796
postprocess: (stops, dispatch, getState) => {
797797
if (params.max && stops.length > params.max) stops = stops.slice(0, params.max)
798-
stops.forEach(stop => dispatch(findRoutesAtStop(stop.id)))
798+
stops.forEach(stop => {
799+
console.log('11', stop.id)
800+
console.log('22', params)
801+
dispatch(findRoutesAtStop(stop.id))
802+
dispatch(findStopTimesForStop({stopId: stop.id}))
803+
})
799804
}
800805
}
801806
)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React, { Component } from 'react'
2+
3+
import { getStopViewerConfig } from '../../util/state'
4+
import { stopTimeComparator } from '../../util/viewer'
5+
6+
import StopTimeCell from './stop-time-cell'
7+
8+
class ChildStopDetails extends Component {
9+
componentDidMount () {
10+
}
11+
12+
getStopTime (childStopTimes) {
13+
let sortedStopTimes = []
14+
sortedStopTimes = childStopTimes
15+
.concat()
16+
.sort(stopTimeComparator)
17+
.slice(0, getStopViewerConfig.numberOfDepartures)
18+
console.log(sortedStopTimes[0])
19+
return sortedStopTimes[0]
20+
}
21+
22+
render () {
23+
const {
24+
childStops,
25+
homeTimezone,
26+
stopViewerArriving,
27+
timeFormat
28+
} = this.props
29+
30+
const showChildStops = childStops?.map(s =>
31+
<div className='childstop__details'>
32+
{/* {s.stopTimes && this.getStopTime(s.stopTimes[0].times)} */}
33+
<div className='childstop__row1'>
34+
<span>
35+
{s.routes && s.routes[0].mode}
36+
</span>
37+
{s.name.charAt(0).toUpperCase()}{s.name.slice(1).toLowerCase()}
38+
<a href='/'>View Details</a>
39+
</div>
40+
<div className='childstop__row2'>
41+
<span className='childstop__route-short-name' style={{ border: '1px solid', borderRadius: '50%', padding: '3px' }}>
42+
{s.routes && s.routes[0].shortName}
43+
</span>
44+
<span>
45+
{s.routes && s.routes[0].longName}
46+
</span>
47+
{s.stopTimes && (
48+
<div className='next-trip-preview'>
49+
<StopTimeCell
50+
homeTimezone={homeTimezone}
51+
soonText={stopViewerArriving}
52+
stopTime={this.getStopTime(s.stopTimes[0].times)}
53+
timeFormat={timeFormat}
54+
/>
55+
</div>)}
56+
</div>
57+
</div>
58+
)
59+
return (
60+
<>
61+
<h3>Related Stops</h3>
62+
<ul>{showChildStops}</ul>
63+
</>
64+
)
65+
}
66+
}
67+
68+
export default ChildStopDetails

lib/components/viewers/child-stop-viewer.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

lib/components/viewers/stop-time-cell.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const StopTimeCell = ({
3232
// 48:00 hours (or more) from the start of the service day.
3333
const departureTimeRemainder = departureTime % ONE_DAY_IN_SECONDS
3434
const daysAfterServiceDay = (departureTime - departureTimeRemainder) / ONE_DAY_IN_SECONDS
35-
const departureDay = serviceDay.add(daysAfterServiceDay, 'day')
36-
const vehicleDepartsToday = now.dayOfYear() === departureDay.dayOfYear()
35+
const departureDay = serviceDay?.add(daysAfterServiceDay, 'day')
36+
const vehicleDepartsToday = now?.dayOfYear() === departureDay?.dayOfYear()
3737

3838
// Determine whether to show departure as countdown (e.g. "5 min") or as HH:mm
3939
// time, using realtime updates if available.

lib/components/viewers/stop-viewer.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as uiActions from '../../actions/ui'
1414
import Icon from '../narrative/icon'
1515
import { getShowUserSettings, getStopViewerConfig } from '../../util/state'
1616

17-
import ChildStopViewer from './child-stop-viewer'
17+
import ChildStopDetails from './child-stop-viewer'
1818
import LiveStopTimes from './live-stop-times'
1919
import StopScheduleTable from './stop-schedule-table'
2020

@@ -72,7 +72,7 @@ class StopViewer extends Component {
7272

7373
componentDidMount () {
7474
// Load the viewed stop in the store when the Stop Viewer first mounts
75-
this.props.findStop({ stopId: this.props.viewedStop.stopId })
75+
this.props.fetchStopInfo(this.props.viewedStop)
7676
console.log('this.props.viewedStop.stopId', this.props.viewedStop.stopId)
7777
}
7878

@@ -108,7 +108,7 @@ class StopViewer extends Component {
108108
) {
109109
// Reset state to default if stop changes (i.e., show next arrivals).
110110
this.setState(defaultState)
111-
this.props.findStop({ stopId: this.props.viewedStop.stopId })
111+
this.props.fetchStopInfo(this.props.viewedStop)
112112
}
113113
}
114114

@@ -228,7 +228,6 @@ class StopViewer extends Component {
228228
const {
229229
autoRefreshStopTimes,
230230
childStops,
231-
findStop,
232231
findStopTimesForStop,
233232
homeTimezone,
234233
stopData,
@@ -283,8 +282,7 @@ class StopViewer extends Component {
283282
<Scrollable>
284283
{contents}
285284
{!scheduleView &&
286-
// <RelatedStops childStops={childStops} />
287-
<ChildStopViewer childStops={childStops} findStops={findStop} />
285+
<ChildStopDetails childStops={childStops} parentStop={stopData} />
288286
}
289287
</Scrollable>
290288
{/* Future: add stop details */}
@@ -319,7 +317,7 @@ const mapStateToProps = (state, ownProps) => {
319317
}
320318

321319
const mapDispatchToProps = {
322-
findStop: apiActions.findStop,
320+
fetchStopInfo: apiActions.fetchStopInfo,
323321
findStopTimesForStop: apiActions.findStopTimesForStop,
324322
forgetStop: mapActions.forgetStop,
325323
rememberStop: mapActions.rememberStop,

lib/reducers/create-otp-reducer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ function createOtpReducer (config) {
671671
const stopLookup = {}
672672
stops.forEach(s => {
673673
stopLookup[s.id] = s
674+
console.log(s)
674675
})
675676

676677
const stopIds = stops.map(stop => stop.id) // ['12345', 'abd']

0 commit comments

Comments
 (0)