Skip to content

Commit

Permalink
Reset persisted filters when searching through autosuggest
Browse files Browse the repository at this point in the history
So that we don't keep the filters from our previous, unrelated search.
  • Loading branch information
Adamik10 committed Oct 14, 2024
1 parent 6c2e9c4 commit f540ae5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/apps/search-header/search-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import { useStatistics } from "../../core/statistics/useStatistics";
import { statistics } from "../../core/statistics/statistics";
import HeaderDropdown from "../../components/header-dropdown/HeaderDropdown";
import useFilterHandler from "../search-result/useFilterHandler";

const SearchHeader: React.FC = () => {
const t = useText();
Expand All @@ -46,7 +47,7 @@ const SearchHeader: React.FC = () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [currentlySelectedItem, setCurrentlySelectedItem] = useState<any>("");
const [isAutosuggestOpen, setIsAutosuggestOpen] = useState<boolean>(false);

const { clearFilter } = useFilterHandler();
const {
data,
isLoading,
Expand Down Expand Up @@ -221,6 +222,8 @@ const SearchHeader: React.FC = () => {
name: statistics.autosuggestClick.name,
trackedData: selectedItem.work.titles.main.join(", ")
}).then(() => {
// Before redirecting we need to clean persisted filters from previous search.
clearFilter();
redirectTo(
constructMaterialUrl(materialUrl, selectedItem.work?.workId as WorkId)
);
Expand All @@ -245,7 +248,8 @@ const SearchHeader: React.FC = () => {
}).then(() => {
const { term, facet } =
getAutosuggestCategoryList(t)[highlightedCategoryIndex];

// Before redirecting we need to clean persisted filters from previous search.
clearFilter();
redirectTo(
constructSearchUrlWithFilter({
searchUrl,
Expand All @@ -262,6 +266,8 @@ const SearchHeader: React.FC = () => {
name: statistics.autosuggestClick.name,
trackedData: determineSuggestionTerm(selectedItem)
}).then(() => {
// Before redirecting we need to clean persisted filters from previous search.
clearFilter();
redirectTo(
constructSearchUrl(searchUrl, determineSuggestionTerm(selectedItem))
);
Expand Down

0 comments on commit f540ae5

Please sign in to comment.