Skip to content

Commit

Permalink
front: add rollingStockId in launchPathfinding arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
clarani committed Feb 17, 2025
1 parent 646ebbb commit ab5f5cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ type ManageTrainScheduleContextType = {
pathProperties?: ManageTrainSchedulePathProperties;
setPathProperties: (pathProperties?: ManageTrainSchedulePathProperties) => void;
voltageRanges: RangedValue[];
launchPathfinding: (pathSteps: (PathStep | null)[]) => void;
launchPathfinding: (
steps: (PathStep | null)[],
rollingStockId?: number,
options?: { isInitialization: boolean }
) => void;
pathfindingState: PathfindingState;
infraInfo: { infra?: InfraWithState; reloadCount: number };
/** Operational points along the path (including origin and destination) and vias added by clicking on map */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const ManageTrainSchedule = () => {
(_rollingStockId: number, comfort: Comfort) => {
dispatch(updateRollingStockID(_rollingStockId));
dispatch(updateRollingStockComfort(comfort));
launchPathfinding(pathSteps);
launchPathfinding(pathSteps, _rollingStockId);
},
[pathSteps]
);
Expand Down
12 changes: 8 additions & 4 deletions front/src/modules/pathfinding/hooks/usePathfinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const usePathfinding = (
const powerRestrictions = useSelector(getPowerRestrictions);
const { infra, reloadCount, setIsInfraError } = useInfraStatus();
const { getRollingStockID } = useOsrdConfSelectors();
const rollingStockId = useSelector(getRollingStockID);
const currentRollingStockId = useSelector(getRollingStockID);

const [pathfindingState, setPathfindingState] =
useState<PathfindingState>(initialPathfindingState);
Expand Down Expand Up @@ -165,7 +165,11 @@ const usePathfinding = (
};

const launchPathfinding = useCallback(
async (steps: (PathStep | null)[], options = { isInitialization: false }) => {
async (
steps: (PathStep | null)[],
rollingStockId = currentRollingStockId,
options = { isInitialization: false }
) => {
if (!options.isInitialization) {
dispatch(replaceItinerary(steps));
if (!isEmptyArray(powerRestrictions)) {
Expand Down Expand Up @@ -264,12 +268,12 @@ const usePathfinding = (
}
}
},
[rollingStockId, infra]
[currentRollingStockId, infra]
);

useEffect(() => {
if (infra?.state === 'CACHED') {
launchPathfinding(pathSteps, { isInitialization: true });
launchPathfinding(pathSteps, currentRollingStockId, { isInitialization: true });
}
}, [infra?.state]);

Expand Down

0 comments on commit ab5f5cc

Please sign in to comment.