Skip to content

Commit

Permalink
Show Next Block on Line Stops
Browse files Browse the repository at this point in the history
  • Loading branch information
consindo committed Mar 29, 2020
1 parent d880aeb commit a5324de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
39 changes: 25 additions & 14 deletions js/views/lines/Line.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,6 @@ class Line extends React.Component {

interpolatedShape = null

state = {
color: '#666',
stops: [],
lineMetadata: [],
timetable: [],
realtimeStopUpdates: {},
loading: true,
currentTrip: null,
vehiclepos: [],
isShapeLoaded: false,
}

tripStops = []

constructor(props) {
Expand All @@ -109,10 +97,24 @@ class Line extends React.Component {
route_short_name: match.params.route_short_name,
agency_id: match.params.agency_id,
route_id: parsed.route_id || null,
trip_id: parsed.trip_id || null,
stop_id: parsed.stop_id || null,
direction_id: parsed.direction === '1' ? 1 : 0,
})

this.state = {
color: '#666',
stops: [],
lineMetadata: [],
timetable: [],
realtimeStopUpdates: {},
loading: true,
currentTrip: parsed.trip_id || null,
nextBlock: null,
vehiclepos: [],
isShapeLoaded: false,
}

if (
UiStore.state.lastTransition !== 'backward' &&
UiStore.state.cardPosition === 'max'
Expand Down Expand Up @@ -224,7 +226,9 @@ class Line extends React.Component {
return service
}),
}
if (newState.timetable.length > 0) {
if (this.state.currentTrip !== null) {
newState.currentTrip = this.state.currentTrip
} else if (newState.timetable.length > 0) {
const selectedTrip = newState.timetable.find(a => a.visible === true)
if (selectedTrip) {
newState.currentTrip = selectedTrip.trip_id
Expand Down Expand Up @@ -306,6 +310,7 @@ class Line extends React.Component {
getStops = async () => {
const { currentTrip } = this.state
const { match } = this.props

this.lineData.trip_id = currentTrip
const data = await this.lineData.getTripStops()
this.tripStops = data.current
Expand All @@ -316,7 +321,11 @@ class Line extends React.Component {
match.params.region,
data.routeInfo.route_short_name
)
this.setState({ stops: renderedStops, loading: false })
this.setState({
stops: renderedStops,
nextBlock: data.next,
loading: false,
})
this.interpolateShape()
}

Expand Down Expand Up @@ -414,6 +423,7 @@ class Line extends React.Component {
currentTrip,
realtimeStopUpdates,
vehiclepos,
nextBlock,
} = this.state
const currentLine =
lineMetadata.length > 0
Expand Down Expand Up @@ -468,6 +478,7 @@ class Line extends React.Component {
currentTrip={currentTrip}
realtimeStopUpdates={realtimeStopUpdates}
isTwentyFourHour={SettingsStore.state.isTwentyFourHour}
nextBlock={nextBlock}
/>
</>
)
Expand Down
10 changes: 8 additions & 2 deletions js/views/lines/LineStops.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const LineStops = ({
}
comparisionStopTime.setSeconds(0) // so it makes more sense in the UI

console.log(nextBlock)
return (
<>
{!showAll && selectedStopIndex > 0 ? (
Expand Down Expand Up @@ -153,7 +152,14 @@ export const LineStops = ({
{nextBlock ? (
<View style={[stopStyle, { borderColor: nextBlock.route_color }]}>
<View style={styles.bullet} />
<TouchableOpacity style={[styles.controls]}>
<TouchableOpacity
style={[styles.controls]}
onClick={() =>
UiStore.safePush(
`/l/${region}/${nextBlock.agency_id}/${nextBlock.route_short_name}?trip_id=${nextBlock.trip_id}&route_id=${nextBlock.route_id}&direction_id=${nextBlock.direction_id}`
)
}
>
<View style={styles.contentContainer}>
<Text style={styles.nextBlockLabel}>Service continues as</Text>
<View style={styles.nextBlockName}>
Expand Down

0 comments on commit a5324de

Please sign in to comment.