Skip to content

Commit c731ed0

Browse files
committed
Fix bug in search by stop area
1 parent 56c9c04 commit c731ed0

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

ui/src/components/stop-registry/search/components/StopPlaceSharedComponents/StopPlaceSearchResults.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ComponentType, FC } from 'react';
1+
import { ComponentType, FC, useEffect } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { TranslationKey } from '../../../../../i18n';
44
import { LoadingWrapper } from '../../../../../uiComponents/LoadingWrapper';
@@ -36,21 +36,43 @@ export const StopPlaceSearchResults: FC<StopPlaceSearchResultsProps> = ({
3636
filters,
3737
sortingInfo: { sortBy },
3838
},
39+
historyState,
40+
setHistoryState,
3941
} = useStopSearchRouterState();
4042

4143
const { stopPlaces, loading } = useFindStopPlaces(filters, placeType);
4244

4345
const groupByArea =
4446
sortBy === groupingField || sortBy === SortStopsBy.DEFAULT;
4547

48+
// When switching back to grouped view, knownStopIds may still be in 'flat'
49+
// mode. Reset it to 'grouped'.
50+
useEffect(() => {
51+
if (!groupByArea) {
52+
return;
53+
}
54+
setHistoryState((p) => {
55+
if (p.knownStopIds.listingMode === 'grouped') {
56+
return p;
57+
}
58+
return {
59+
...p,
60+
knownStopIds: { listingMode: 'grouped', ids: [], groups: {} },
61+
};
62+
});
63+
}, [groupByArea, setHistoryState]);
64+
65+
const isReadyToShowGrouped =
66+
groupByArea && historyState.knownStopIds.listingMode === 'grouped';
67+
4668
return (
4769
<LoadingWrapper
4870
className="flex justify-center"
4971
loadingText={t('search.searching')}
5072
loading={stopPlaces.length === 0 ? loading : false}
5173
testId={testIds.loadingSearchResults}
5274
>
53-
{groupByArea ? (
75+
{isReadyToShowGrouped ? (
5476
<SearchGroupedStopsResults
5577
groupingField={groupingField}
5678
stopPlaces={stopPlaces}

0 commit comments

Comments
 (0)