Skip to content

Commit

Permalink
fix: filter out next legs too far in the future
Browse files Browse the repository at this point in the history
  • Loading branch information
tekoiv committed Sep 19, 2023
1 parent fc5cc29 commit 2c92c9f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/component/TransitLeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class TransitLeg extends React.Component {
};
}

// Some next legs might be for example 24h in the future which seems confusing. Only show alternatives that are less than 12h in the future.
filterNextLegs = leg =>
leg.nextLegs.filter(
nextLeg =>
moment(nextLeg.startTime).diff(moment(leg.startTime), 'hours') < 12,
);

stopCode = stopCode => stopCode && <StopCode code={stopCode} />;

isRouteConstantOperation = () =>
Expand All @@ -57,7 +64,7 @@ class TransitLeg extends React.Component {

displayAlternativeLegs = () =>
!!this.context.config.showAlternativeLegs &&
this.props.leg.nextLegs?.length > 0 &&
this.filterNextLegs(this.props.leg).length > 0 &&
!this.isRouteConstantOperation();

toggleShowIntermediateStops = () => {
Expand Down Expand Up @@ -465,7 +472,7 @@ class TransitLeg extends React.Component {
))}
{this.displayAlternativeLegs() && (
<AlternativeLegsInfo
legs={leg.nextLegs}
legs={this.filterNextLegs(leg)}
showAlternativeLegs={this.state.showAlternativeLegs}
toggle={() =>
this.setState(prevState => ({
Expand Down

0 comments on commit 2c92c9f

Please sign in to comment.