diff --git a/govtool/frontend/src/components/organisms/DashboardGovernanceActions.tsx b/govtool/frontend/src/components/organisms/DashboardGovernanceActions.tsx index b1b4f80e1..ccdf0b84c 100644 --- a/govtool/frontend/src/components/organisms/DashboardGovernanceActions.tsx +++ b/govtool/frontend/src/components/organisms/DashboardGovernanceActions.tsx @@ -22,6 +22,7 @@ import { DashboardGovernanceActionsVotedOn, } from "@organisms"; import { Button } from "@atoms"; +import usePrevious from "@/hooks/usePrevious"; type TabPanelProps = { children?: React.ReactNode; @@ -84,11 +85,17 @@ export const DashboardGovernanceActions = () => { const queryFilters = chosenFilters.length > 0 ? chosenFilters : defaultCategories; + const prevFilters = usePrevious(queryFilters); + const prevSorting = usePrevious(chosenSorting); + + const stableFilters = isAdjusting ? prevFilters ?? queryFilters : queryFilters; + const stableSorting = isAdjusting ? prevSorting ?? chosenSorting : chosenSorting; + const { proposals, isProposalsLoading } = useGetProposalsQuery({ - filters: queryFilters, - sorting: chosenSorting, + filters: stableFilters, + sorting: stableSorting, searchPhrase: debouncedSearchText, - enabled: !isAdjusting, + enabled: true, }); const { data: votes, areDRepVotesLoading } = useGetDRepVotesQuery( queryFilters, diff --git a/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts b/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts index 0ebbe8677..f377ab128 100644 --- a/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts +++ b/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts @@ -33,15 +33,16 @@ export const useGetProposalsQuery = ({ return allProposals.flatMap((proposal) => proposal.elements); }; - const { data, isLoading } = useQuery( - [QUERY_KEYS.useGetProposalsKey, filters, searchPhrase, sorting, dRepID], - fetchProposals, - { - enabled, - refetchOnWindowFocus: true, - keepPreviousData: true, - }, - ); + const { data, isLoading } = useQuery( + [QUERY_KEYS.useGetProposalsKey, filters, searchPhrase, sorting, dRepID], + fetchProposals, + { + enabled, + refetchOnWindowFocus: true, + keepPreviousData: true, + staleTime: 2000, + }, + ); const proposals = Object.values(groupByType(data) ?? []);