Skip to content

Commit

Permalink
front: fix missing rolling stock images in train schedule list
Browse files Browse the repository at this point in the history
We were calling formatTrainScheduleSummaries() before the rolling
stock list got fetched. As a result all rolling stocks in the
formatted train schedule summaries were null on first load.

Wait for the rolling stock list to be available before kicking off
the train schedule summaries lazy loading.
  • Loading branch information
emersion authored and SharglutDev committed Sep 12, 2024
1 parent 5527122 commit f6a953b
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const useLazyLoadTrains = ({
const [postTrainScheduleSimulationSummary] =
osrdEditoastApi.endpoints.postTrainScheduleSimulationSummary.useLazyQuery();

const { data: { results: rollingStocks } = { results: [] } } =
const { data: { results: rollingStocks } = { results: null } } =
osrdEditoastApi.endpoints.getLightRollingStock.useQuery({ pageSize: 1000 });

const trainSchedulesById = useMemo(() => mapBy(trainSchedules, 'id'), [trainSchedules]);
Expand Down Expand Up @@ -103,7 +103,7 @@ const useLazyLoadTrains = ({
packageToFetch,
rawSummaries,
trainSchedulesById,
rollingStocks
rollingStocks!
);

// as formattedSummaries is a dictionary, we replace the previous values with the new ones
Expand All @@ -115,10 +115,10 @@ const useLazyLoadTrains = ({
setAllTrainsLoaded(true);
};

if (infraId && trainIdsToFetch && trainIdsToFetch.length > 0) {
if (infraId && trainIdsToFetch && rollingStocks && trainIdsToFetch.length > 0) {
getTrainScheduleSummaries(infraId, trainIdsToFetch);
}
}, [infraId, trainIdsToFetch]);
}, [infraId, trainIdsToFetch, rollingStocks]);

return {
trainScheduleSummariesById,
Expand Down

0 comments on commit f6a953b

Please sign in to comment.