Skip to content

Commit

Permalink
fix: passing random sorting to governance actions request
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Jan 10, 2025
1 parent a06cbf4 commit b916ee6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 9 additions & 6 deletions govtool/frontend/src/context/dataActionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, {
useEffect,
useMemo,
FC,
useRef,
} from "react";
import { useLocation } from "react-router-dom";

Expand Down Expand Up @@ -41,7 +42,7 @@ interface ProviderProps {
}

const DataActionsBarProvider: FC<ProviderProps> = ({ children }) => {
const [isAdjusting, setIsAdjusting] = useState<boolean>(true);
const isAdjusting = useRef<boolean>(false);
const [searchText, setSearchText] = useState<string>("");
const debouncedSearchText = useDebounce(searchText, 300);
const [filtersOpen, setFiltersOpen] = useState<boolean>(false);
Expand All @@ -64,11 +65,12 @@ const DataActionsBarProvider: FC<ProviderProps> = ({ 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/");
Expand All @@ -77,7 +79,8 @@ const DataActionsBarProvider: FC<ProviderProps> = ({ children }) => {
pathname.includes("governance_actions/category");

useEffect(() => {
setIsAdjusting(true);
isAdjusting.current = true;

if (
(!pathname.includes("drep_directory") &&
userMovedToDifferentAppArea &&
Expand All @@ -94,7 +97,7 @@ const DataActionsBarProvider: FC<ProviderProps> = ({ children }) => {

const contextValue = useMemo(
() => ({
isAdjusting,
isAdjusting: isAdjusting.current,
chosenFilters,
chosenFiltersLength: chosenFilters.length,
chosenSorting,
Expand All @@ -111,7 +114,6 @@ const DataActionsBarProvider: FC<ProviderProps> = ({ children }) => {
sortOpen,
}),
[
isAdjusting,
chosenFilters,
chosenSorting,
debouncedSearchText,
Expand All @@ -120,6 +122,7 @@ const DataActionsBarProvider: FC<ProviderProps> = ({ children }) => {
sortOpen,
closeFilters,
closeSorts,
pathname,
],
);

Expand Down
4 changes: 3 additions & 1 deletion govtool/frontend/src/pages/GovernanceActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -37,6 +38,7 @@ export const GovernanceActions = () => {
filters: queryFilters,
sorting: chosenSorting,
searchPhrase: debouncedSearchText,
enabled: !isAdjusting,
});

useEffect(() => {
Expand Down

0 comments on commit b916ee6

Please sign in to comment.