Skip to content

Commit

Permalink
prevent resetting the filters cache on page load (#7009)
Browse files Browse the repository at this point in the history
* fixes #7008; fix resetting the filters on page visit

* fix existing filters not being cleared

* fix
  • Loading branch information
rithviknishad authored Jan 12, 2024
1 parent dfe9923 commit 0667894
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Common/hooks/useFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useQueryParams } from "raviger";
import { QueryParam, setQueryParamsOptions, useQueryParams } from "raviger";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import GenericFilterBadge from "../../CAREUI/display/FilterBadge";
Expand All @@ -23,7 +23,15 @@ export default function useFilters({ limit = 14 }: { limit?: number }) {
const { kasp_string } = useConfig();
const hasPagination = limit > 0;
const [showFilters, setShowFilters] = useState(false);
const [qParams, setQueryParams] = useQueryParams();
const [qParams, _setQueryParams] = useQueryParams();

const setQueryParams = (
query: QueryParam,
options?: setQueryParamsOptions
) => {
_setQueryParams(query, options);
updateFiltersCache(query);
};

const updateQuery = (filter: FilterState) => {
filter = hasPagination ? { page: 1, limit, ...filter } : filter;
Expand All @@ -38,8 +46,6 @@ export default function useFilters({ limit = 14 }: { limit?: number }) {
};
const removeFilter = (param: string) => removeFilters([param]);

useEffect(() => updateFiltersCache(qParams), [qParams]);

useEffect(() => {
const cache = getFiltersCache();
const qParamKeys = Object.keys(qParams);
Expand Down

0 comments on commit 0667894

Please sign in to comment.