Skip to content

Commit

Permalink
fix - display search results coming back from immersion offer
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementLmd committed Sep 11, 2024
1 parent 3beb928 commit 9528ae8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions front/src/app/pages/search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SectionTextEmbed,
} from "react-design-system";
import { useForm, useWatch } from "react-hook-form";
import { useDispatch } from "react-redux";
import { LatLonDistance, SearchSortedBy, ValueOf, domElementIds } from "shared";
import { AppellationAutocomplete } from "src/app/components/forms/autocomplete/AppellationAutocomplete";
import { PlaceAutocomplete } from "src/app/components/forms/autocomplete/PlaceAutocomplete";
Expand All @@ -29,6 +30,7 @@ import { searchSelectors } from "src/core-logic/domain/search/search.selectors";
import {
SearchPageParams,
initialState,
searchSlice,
} from "src/core-logic/domain/search/search.slice";
import { useStyles } from "tss-react/dsfr";
import { Route } from "type-route";
Expand Down Expand Up @@ -63,6 +65,7 @@ export const SearchPage = ({
useNaturalLanguageForAppellations?: boolean;
}) => {
const { cx } = useStyles();
const dispatch = useDispatch();
const initialSearchSliceState = initialState;
const searchStatus = useAppSelector(searchSelectors.searchStatus);
const searchResults = useAppSelector(searchSelectors.searchResults);
Expand Down Expand Up @@ -145,6 +148,12 @@ export const SearchPage = ({
formValues,
]);

useEffect(() => {
return () => {
dispatch(searchSlice.actions.clearSearchStatus());
};
}, [dispatch]);

return (
<HeaderFooterLayout>
<MainWrapper vSpacing={0} layout="fullscreen">
Expand Down
3 changes: 3 additions & 0 deletions front/src/core-logic/domain/search/search.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@ export const searchSlice = createSlice({
state.currentSearchResult = initialState.currentSearchResult;
state.feedback = initialState.feedback;
},
clearSearchStatus: (state) => {
state.searchStatus = initialState.searchStatus;
},
},
});
17 changes: 17 additions & 0 deletions front/src/core-logic/domain/search/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,23 @@ describe("search epic", () => {
);
});

it("should reset search status when clicking on an offer", () => {
expectStatus("noSearchMade");
store.dispatch(
searchSlice.actions.searchRequested({
sortedBy: "distance",
distanceKm: 10,
latitude: immersionOffer.position.lat,
longitude: immersionOffer.position.lon,
}),
);
feedWithSearchResults([]);
feedWithSearchResults([]);
expectStatus("ok");
store.dispatch(searchSlice.actions.clearSearchStatus());
expectStatus("noSearchMade");
});

const expectStateToMatchInitialState = () => {
expectToEqual(store.getState().search, initialState);
};
Expand Down

0 comments on commit 9528ae8

Please sign in to comment.