Skip to content

Commit

Permalink
front: fetch directly rollingStock in usePathfinding
Browse files Browse the repository at this point in the history
Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
clarani committed Feb 12, 2025
1 parent 0196665 commit c667a50
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions front/src/modules/pathfinding/hooks/usePathfinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import type {
PostInfraByInfraIdPathPropertiesApiArg,
} from 'common/api/osrdEditoastApi';
import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
import { useOsrdConfSelectors } from 'common/osrdContext';
import {
formatSuggestedOperationalPoints,
getPathfindingQuery,
matchPathStepAndOp,
} from 'modules/pathfinding/utils';
import { useStoreDataForRollingStockSelector } from 'modules/rollingStock/components/RollingStockSelector/useStoreDataForRollingStockSelector';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import { setFailure, setWarning } from 'reducers/main';
import { replaceItinerary, updatePathSteps } from 'reducers/osrdconf/operationalStudiesConf';
Expand Down Expand Up @@ -51,11 +51,14 @@ const usePathfinding = (
const pathSteps = useSelector(getPathSteps);
const powerRestrictions = useSelector(getPowerRestrictions);
const { infra, reloadCount, setIsInfraError } = useInfraStatus();
const { rollingStock } = useStoreDataForRollingStockSelector();
const { getRollingStockID } = useOsrdConfSelectors();
const rollingStockId = useSelector(getRollingStockID);

const [pathfindingState, setPathfindingState] =
useState<PathfindingState>(initialPathfindingState);

const [getRollingStockById] =
osrdEditoastApi.endpoints.getRollingStockByRollingStockId.useLazyQuery();
const [postPathfindingBlocks] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useLazyQuery();
const [postPathProperties] =
Expand Down Expand Up @@ -186,6 +189,10 @@ const usePathfinding = (
}

setIsRunning();

const rollingStock = rollingStockId
? await getRollingStockById({ rollingStockId }).unwrap()
: undefined;
const pathfindingInput = getPathfindingQuery({
infraId,
rollingStock,
Expand Down Expand Up @@ -257,7 +264,7 @@ const usePathfinding = (
}
}
},
[rollingStock, infra]
[rollingStockId, infra]
);

useEffect(() => {
Expand Down

0 comments on commit c667a50

Please sign in to comment.