Skip to content

Commit

Permalink
fix: next leg cannot be wait leg
Browse files Browse the repository at this point in the history
Flapping fix accidentally broke most transfer related notifiers
  • Loading branch information
vesameskanen committed Dec 22, 2024
1 parent 8a35477 commit 0dc3f7a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/component/itinerary/navigator/hooks/useRealtimeLegs.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,11 @@ function getLegsOfInterest(initialLegs, time, previousFinishedLeg) {
return acc;
}, []);

const nextLegIdx = legs.findIndex(({ start }) => legTime(start) > time);
let currentLeg = legs.find(
({ start, end }) => legTime(start) <= time && legTime(end) >= time,
);
let previousLeg = legs.findLast(({ end }) => legTime(end) < time);
let nextLeg = legs[nextLegIdx];
const nextLeg = legs.find(({ start }) => legTime(start) > time);

// Indices are shifted by one if a previously completed leg reappears as current.
if (
Expand All @@ -135,15 +134,14 @@ function getLegsOfInterest(initialLegs, time, previousFinishedLeg) {
) {
previousLeg = currentLeg;
currentLeg = nextLeg;
nextLeg = nextLegIdx !== -1 ? legs[nextLegIdx + 1] : undefined;
}

return {
firstLeg: legs[0],
lastLeg: legs[legs.length - 1],
previousLeg,
currentLeg,
nextLeg,
nextLeg: initialLegs.find(({ start }) => legTime(start) > time),
};
}

Expand Down

0 comments on commit 0dc3f7a

Please sign in to comment.