Skip to content

Commit 0b3faca

Browse files
committed
front: fix infinite loop after rtk query
Signed-off-by: SarahBellaha <sarah.bellaha@sncf.fr>
1 parent 169bca1 commit 0b3faca

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

front/src/applications/stdcm/hooks/useStdcmPathfinding.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const useStdcmPathfinding = (infra?: InfraWithState) => {
3737
}, [pathSteps]);
3838

3939
const pathfindingPayload = useMemo(() => {
40-
if (infra?.state !== 'CACHED' || !rollingStock || pathStepsLocations.length < 2) {
40+
if (infra?.state !== 'CACHED' || pathStepsLocations.length < 2) {
4141
return null;
4242
}
4343
return getPathfindingQuery({
@@ -47,28 +47,27 @@ const useStdcmPathfinding = (infra?: InfraWithState) => {
4747
});
4848
}, [pathStepsLocations, rollingStock, infra]);
4949

50-
const { pathfinding, isFetching } =
50+
const { data: pathfinding, isFetching } =
5151
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useQuery(pathfindingPayload!, {
5252
skip: !pathfindingPayload,
53-
selectFromResult: (response) => {
54-
const pathProperties = usePathProperties(
55-
infra?.id,
56-
response?.data?.status === 'success' ? response.data : undefined,
57-
['geometry']
58-
);
59-
return {
60-
...response,
61-
pathfinding: response.data
62-
? {
63-
status: response.data.status,
64-
geometry: pathProperties?.geometry ?? undefined,
65-
}
66-
: null,
67-
};
68-
},
6953
});
7054

71-
return { isPathfindingLoading: isFetching, pathfinding };
55+
const pathProperties = usePathProperties(
56+
infra?.id,
57+
pathfinding?.status === 'success' ? pathfinding : undefined,
58+
['geometry']
59+
);
60+
61+
const pathfindingResult = useMemo(() => {
62+
return pathfinding
63+
? {
64+
status: pathfinding.status,
65+
geometry: pathProperties?.geometry ?? undefined,
66+
}
67+
: null;
68+
}, [pathfinding]);
69+
70+
return { isPathfindingLoading: isFetching, pathfinding: pathfindingResult };
7271
};
7372

7473
export default useStdcmPathfinding;

0 commit comments

Comments
 (0)