Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
DashboardGovernanceActionsVotedOn,
} from "@organisms";
import { Button } from "@atoms";
import usePrevious from "@/hooks/usePrevious";

type TabPanelProps = {
children?: React.ReactNode;
Expand Down Expand Up @@ -85,21 +84,11 @@ 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: stableFilters,
sorting: stableSorting,
filters: queryFilters,
sorting: chosenSorting,
searchPhrase: debouncedSearchText,
enabled: voter?.isRegisteredAsDRep || voter?.isRegisteredAsSoleVoter,
enabled: !isAdjusting,
});
const { data: votes, areDRepVotesLoading } = useGetDRepVotesQuery(
queryFilters,
Expand All @@ -109,31 +98,31 @@ export const DashboardGovernanceActions = () => {

// White Magic :)
const shouldFilter =
voter?.isRegisteredAsDRep || voter?.isRegisteredAsSoleVoter;

const filteredProposals = useMemo(() => {
if (!shouldFilter || !proposals || !votes) return proposals;

return proposals
.map((proposalCategory) => {
const filteredActions = proposalCategory.actions.filter((action) => {
const hasVote = votes.some((voteCategory) =>
voteCategory.actions.some(
(voteAction) =>
voteAction.proposal.txHash === action.txHash &&
voteAction.proposal.index === action.index,
),
);
return !hasVote;
});

return {
...proposalCategory,
actions: filteredActions,
};
})
.filter((category) => category.actions.length > 0);
}, [proposals, votes, shouldFilter]);
voter?.isRegisteredAsDRep || voter?.isRegisteredAsSoleVoter;

const filteredProposals = useMemo(() => {
if (!shouldFilter || !proposals || !votes) return proposals;

return proposals
.map((proposalCategory) => {
const filteredActions = proposalCategory.actions.filter((action) => {
const hasVote = votes.some((voteCategory) =>
voteCategory.actions.some(
(voteAction) =>
voteAction.proposal.txHash === action.txHash &&
voteAction.proposal.index === action.index,
),
);
return !hasVote;
});

return {
...proposalCategory,
actions: filteredActions,
};
})
.filter((category) => category.actions.length > 0);
}, [proposals, votes, shouldFilter]);

const { state } = useLocation();
const [content, setContent] = useState<number>(
Expand Down