From b916ee6197c3a12f505963a6565c19f81f2401ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Fri, 10 Jan 2025 12:35:24 +0100 Subject: [PATCH] fix: passing random sorting to governance actions request --- CHANGELOG.md | 1 + govtool/frontend/src/context/dataActionsBar.tsx | 15 +++++++++------ govtool/frontend/src/pages/GovernanceActions.tsx | 4 +++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb1876532..8ac7ba6f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ changes. - Fix counting submitted votes [Issue 2609](https://github.com/IntersectMBO/govtool/issues/2609) - Fix opening relative paths in external links +- Fix passing random sorting to governance actions on disconnected wallet ### Changed diff --git a/govtool/frontend/src/context/dataActionsBar.tsx b/govtool/frontend/src/context/dataActionsBar.tsx index fd18ee55a..9955ec268 100644 --- a/govtool/frontend/src/context/dataActionsBar.tsx +++ b/govtool/frontend/src/context/dataActionsBar.tsx @@ -8,6 +8,7 @@ import React, { useEffect, useMemo, FC, + useRef, } from "react"; import { useLocation } from "react-router-dom"; @@ -41,7 +42,7 @@ interface ProviderProps { } const DataActionsBarProvider: FC = ({ children }) => { - const [isAdjusting, setIsAdjusting] = useState(true); + const isAdjusting = useRef(false); const [searchText, setSearchText] = useState(""); const debouncedSearchText = useDebounce(searchText, 300); const [filtersOpen, setFiltersOpen] = useState(false); @@ -64,11 +65,12 @@ const DataActionsBarProvider: FC = ({ children }) => { setSearchText(""); setChosenFilters([]); setChosenSorting(""); - setIsAdjusting(false); + isAdjusting.current = false; }, []); const userMovedToDifferentAppArea = - pathname !== lastPath && !pathname.startsWith(lastPath); + pathname !== lastPath && + (!pathname.startsWith(lastPath) || lastPath === ""); const userOpenedGADetailsFromCategoryPage = lastPath.includes("governance_actions/category") && pathname.includes("governance_actions/"); @@ -77,7 +79,8 @@ const DataActionsBarProvider: FC = ({ children }) => { pathname.includes("governance_actions/category"); useEffect(() => { - setIsAdjusting(true); + isAdjusting.current = true; + if ( (!pathname.includes("drep_directory") && userMovedToDifferentAppArea && @@ -94,7 +97,7 @@ const DataActionsBarProvider: FC = ({ children }) => { const contextValue = useMemo( () => ({ - isAdjusting, + isAdjusting: isAdjusting.current, chosenFilters, chosenFiltersLength: chosenFilters.length, chosenSorting, @@ -111,7 +114,6 @@ const DataActionsBarProvider: FC = ({ children }) => { sortOpen, }), [ - isAdjusting, chosenFilters, chosenSorting, debouncedSearchText, @@ -120,6 +122,7 @@ const DataActionsBarProvider: FC = ({ children }) => { sortOpen, closeFilters, closeSorts, + pathname, ], ); diff --git a/govtool/frontend/src/pages/GovernanceActions.tsx b/govtool/frontend/src/pages/GovernanceActions.tsx index adde3685f..f2f26ceb1 100644 --- a/govtool/frontend/src/pages/GovernanceActions.tsx +++ b/govtool/frontend/src/pages/GovernanceActions.tsx @@ -23,7 +23,8 @@ const defaultCategories = GOVERNANCE_ACTIONS_FILTERS.map( ); export const GovernanceActions = () => { - const { debouncedSearchText, ...dataActionsBarProps } = useDataActionsBar(); + const { debouncedSearchText, isAdjusting, ...dataActionsBarProps } = + useDataActionsBar(); const { chosenFilters, chosenSorting } = dataActionsBarProps; const { isMobile, pagePadding } = useScreenDimension(); const { isEnabled } = useCardano(); @@ -37,6 +38,7 @@ export const GovernanceActions = () => { filters: queryFilters, sorting: chosenSorting, searchPhrase: debouncedSearchText, + enabled: !isAdjusting, }); useEffect(() => {