diff --git a/govtool/frontend/src/context/dataActionsBar.tsx b/govtool/frontend/src/context/dataActionsBar.tsx index 9ef913a26..e2776346c 100644 --- a/govtool/frontend/src/context/dataActionsBar.tsx +++ b/govtool/frontend/src/context/dataActionsBar.tsx @@ -68,18 +68,32 @@ const DataActionsBarProvider: FC = ({ children }) => { isAdjusting.current = false; }, []); + const gADetailsPathnameRegexp = /^.*\/governance_actions\/[a-fA-F0-9]{64}$/; const userMovedToDifferentAppArea = pathname !== lastPath && (!pathname.startsWith(lastPath) || lastPath === "" || lastPath === "/"); + const userOpenedGADetails = gADetailsPathnameRegexp.test(pathname); const userOpenedGADetailsFromCategoryPage = - lastPath.includes("governance_actions/category") && - pathname.includes("governance_actions/"); + userOpenedGADetails && + lastPath.includes("governance_actions/category"); const userMovedFromGAListToCategoryPage = lastPath.endsWith("governance_actions") && pathname.includes("governance_actions/category"); + const userMovedFromGADetailsToListOrCategoryPage = + (gADetailsPathnameRegexp.test(lastPath) && + pathname.includes("governance_actions")) || + pathname.includes("governance_actions/category"); useEffect(() => { isAdjusting.current = true; + if (userOpenedGADetails) { + return; + } + + if (userMovedFromGADetailsToListOrCategoryPage && debouncedSearchText.length > 0) { + isAdjusting.current = false; + return; + } if ( (!pathname.includes("drep_directory") && @@ -93,7 +107,7 @@ const DataActionsBarProvider: FC = ({ children }) => { useEffect(() => { setLastPath(pathname); - }, [searchText, chosenFilters, chosenSorting]); + }, [pathname, searchText, chosenFilters, chosenSorting]); const contextValue = useMemo( () => ({ diff --git a/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts b/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts index bee3cd39d..a21b7b986 100644 --- a/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts +++ b/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts @@ -33,7 +33,7 @@ export const useGetProposalsQuery = ({ return allProposals.flatMap((proposal) => proposal.elements); }; - const { data, isLoading } = useQuery( + const { data, isLoading, isFetching } = useQuery( [ QUERY_KEYS.useGetProposalsKey, filters, @@ -46,16 +46,18 @@ export const useGetProposalsQuery = ({ fetchProposals, { enabled, - refetchOnWindowFocus: true, + refetchOnWindowFocus: false, + refetchOnReconnect: false, keepPreviousData: true, - cacheTime: Infinity, }, ); + const isProposalsLoading = isLoading || isFetching; + const proposals = Object.values(groupByType(data) ?? []); return { - isProposalsLoading: isLoading, + isProposalsLoading, proposals, }; };