Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show alternative later legs from too far in the future #4861

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/component/TransitLeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ 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 => {
if (!leg.nextLegs) {
return [];
}
return leg.nextLegs.filter(
nextLeg =>
moment(nextLeg.startTime).diff(moment(leg.startTime), 'hours') < 12,
);
};

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

isRouteConstantOperation = () =>
Expand All @@ -57,7 +68,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 +476,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
Loading