Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: passing random sorting to governance actions request #2619

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading