Skip to content

Commit

Permalink
front: fix power restrictions reset when editing a train
Browse files Browse the repository at this point in the history
Add a state value isInitialized to avoid reseting the power restrictions when editing a train.
Indeed, the pathfinding was launched by the 2 hooks (with infra and rollingStock), which reset the power restrictions,
even when the user was editing a train. Now it won't be the case anymore.

Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
clarani committed Dec 23, 2024
1 parent 7096406 commit 2b22d28
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions front/src/modules/pathfinding/hooks/usePathfinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const usePathfinding = (
const [pathfindingState, setPathfindingState] =
useState<PathfindingState>(initialPathfindingState);

// isInitialized is used to prevent the pathfinding to be launched multiple times
// and especially to prevent the power restrictions to be reset
const [isInitialized, setIsInitialized] = useState(false);

const [postPathfindingBlocks] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useLazyQuery();
const [postPathProperties] =
Expand Down Expand Up @@ -266,15 +270,21 @@ const usePathfinding = (
);

useEffect(() => {
if (infra?.state === 'CACHED') {
if (isInitialized && infra?.state === 'CACHED') {
launchPathfinding(pathSteps);
}
}, [infra?.state]);

useEffect(() => {
launchPathfinding(pathSteps);
if (isInitialized) {
launchPathfinding(pathSteps);
}
}, [rollingStock]);

useEffect(() => {
setIsInitialized(true);
}, []);

return {
launchPathfinding,
pathfindingState,
Expand Down

0 comments on commit 2b22d28

Please sign in to comment.