diff --git a/govtool/frontend/src/context/dataActionsBar.tsx b/govtool/frontend/src/context/dataActionsBar.tsx index 9ef913a26..d596f5d2f 100644 --- a/govtool/frontend/src/context/dataActionsBar.tsx +++ b/govtool/frontend/src/context/dataActionsBar.tsx @@ -8,7 +8,6 @@ import React, { useEffect, useMemo, FC, - useRef, } from "react"; import { useLocation } from "react-router-dom"; @@ -42,7 +41,7 @@ interface ProviderProps { } const DataActionsBarProvider: FC = ({ children }) => { - const isAdjusting = useRef(false); + const [isAdjusting, setIsAdjusting] = useState(false); const [searchText, setSearchText] = useState(""); const debouncedSearchText = useDebounce(searchText.trim(), 300); const [filtersOpen, setFiltersOpen] = useState(false); @@ -65,7 +64,6 @@ const DataActionsBarProvider: FC = ({ children }) => { setSearchText(""); setChosenFilters([]); setChosenSorting(""); - isAdjusting.current = false; }, []); const userMovedToDifferentAppArea = @@ -79,7 +77,11 @@ const DataActionsBarProvider: FC = ({ children }) => { pathname.includes("governance_actions/category"); useEffect(() => { - isAdjusting.current = true; + setIsAdjusting(true); + + const timeout = setTimeout(() => { + setIsAdjusting(false); + }, 150); // Adjust delay if needed if ( (!pathname.includes("drep_directory") && @@ -89,6 +91,8 @@ const DataActionsBarProvider: FC = ({ children }) => { ) { resetState(); } + + return () => clearTimeout(timeout); }, [pathname, resetState]); useEffect(() => { @@ -97,7 +101,7 @@ const DataActionsBarProvider: FC = ({ children }) => { const contextValue = useMemo( () => ({ - isAdjusting: isAdjusting.current, + isAdjusting, chosenFilters, chosenFiltersLength: chosenFilters.length, chosenSorting,