Skip to content

Commit

Permalink
[#674] GA Search - Voted on - Add search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJaroszczak committed Apr 15, 2024
1 parent 94d1a53 commit c8f1df5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export const DashboardGovernanceActionsVotedOn = ({
searchPhrase,
sorting,
}: DashboardGovernanceActionsVotedOnProps) => {
const { data, areDRepVotesLoading } = useGetDRepVotesQuery(filters, sorting);
const { data, areDRepVotesLoading } = useGetDRepVotesQuery(
filters,
sorting,
searchPhrase,
);
const { isMobile } = useScreenDimension();
const { pendingTransaction } = useCardano();
const { t } = useTranslation();
Expand Down
21 changes: 17 additions & 4 deletions govtool/frontend/src/hooks/queries/useGetDRepVotesQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,30 @@ import { useCardano } from "@context";
import { getDRepVotes } from "@services";
import { VotedProposalToDisplay } from "@/models/api";

export const useGetDRepVotesQuery = (filters: string[], sorting: string) => {
export const useGetDRepVotesQuery = (
type?: string[],
sort?: string,
search?: string,
) => {
const { dRepID, pendingTransaction } = useCardano();

const { data, isLoading, refetch, isRefetching } = useQuery({
queryKey: [
QUERY_KEYS.useGetDRepVotesKey,
pendingTransaction.vote?.transactionHash,
filters,
sorting,
type,
sort,
search,
],
queryFn: () => getDRepVotes({ dRepID, filters, sorting }),
queryFn: () =>
getDRepVotes({
dRepID,
params: {
...(search && { search }),
...(sort && { sort }),
...(type && { type }),
},
}),
enabled: !!dRepID,
});

Expand Down
27 changes: 10 additions & 17 deletions govtool/frontend/src/services/requests/getDRepVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@ import { VotedProposal, VotedProposalToDisplay } from "@models";
import { checkIsMissingGAMetadata } from "@utils";
import { API } from "../API";

type GetDRepVotesParams = {
type?: string[];
sort?: string;
search?: string;
};

export const getDRepVotes = async ({
dRepID,
filters,
sorting,
params,
}: {
dRepID: string;
filters: string[];
sorting: string;
params: GetDRepVotesParams;
}) => {
const urlBase = `/drep/getVotes/${dRepID}`;
let urlParameters = "";
if (filters.length > 0) {
filters.forEach((item) => {
urlParameters += `&type=${item}`;
});
}
if (sorting.length) {
urlParameters += `&sort=${sorting}`;
}
if (urlParameters.length) {
urlParameters = urlParameters.replace("&", "?");
}
const { data } = await API.get<VotedProposal[]>(`${urlBase}${urlParameters}`);

const { data } = await API.get<VotedProposal[]>(urlBase, { params });

const mappedData = (await Promise.all(
data.map(async (proposal) => {
Expand Down

0 comments on commit c8f1df5

Please sign in to comment.