Skip to content

Commit

Permalink
fix(explorer): As a user, I want to have a consistent default sorting…
Browse files Browse the repository at this point in the history
… logic across all the pages in the explorer (#722)
  • Loading branch information
alainncls authored Sep 10, 2024
1 parent d15e000 commit 19beba6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion explorer/src/pages/MyAttestations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const MyAttestations: React.FC = () => {
undefined,
{ subject: address },
"attestedDate",
sortByDateDirection as OrderDirection,
(sortByDateDirection as OrderDirection) || "desc",
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import useSWR from "swr";

import { DataTable } from "@/components/DataTable";
import { columns } from "@/constants/columns/attestation";
import { EQueryParams } from "@/enums/queryParams.ts";
import { SWRKeys } from "@/interfaces/swr/enum";
import { useNetworkContext } from "@/providers/network-provider/context";
import { APP_ROUTES } from "@/routes/constants";
Expand All @@ -17,9 +18,12 @@ export const SearchAttestationsReceived: React.FC<SearchComponentProps> = ({ get
network: { chain },
} = useNetworkContext();

const searchParams = new URLSearchParams(window.location.search);
const sortByDateDirection = searchParams.get(EQueryParams.SORT_BY_DATE);

const { data } = useSWR(
`${SWRKeys.GET_ATTESTATION_LIST}/${SWRKeys.SEARCH}/${search}/${chain.id}`,
async () => loadAttestationReceivedList(sdk.attestation, parsedString),
`${SWRKeys.GET_ATTESTATION_LIST}/${SWRKeys.SEARCH}/${search}/${chain.id}/${sortByDateDirection}`,
async () => loadAttestationReceivedList(sdk.attestation, parsedString, sortByDateDirection),
{
shouldRetryOnError: false,
revalidateAll: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OrderDirection } from "@verax-attestation-registry/verax-sdk/lib/types/.graphclient";
import AttestationDataMapper from "@verax-attestation-registry/verax-sdk/lib/types/src/dataMapper/AttestationDataMapper";

import { ITEMS_SEARCHED_DEFAULT } from "@/constants";
Expand All @@ -8,13 +9,20 @@ import { uniqMap } from "@/utils/searchUtils";
export const loadAttestationReceivedList = async (
attestation: AttestationDataMapper,
parsedString: Partial<ResultParseSearch>,
sortByDateDirection: string | null,
) => {
const [listBySubject] = parsedString.address
? await Promise.all(
parsedString.address.map(async (address) => {
return attestation.findBy(ITEMS_SEARCHED_DEFAULT, undefined, {
subject: address,
});
return attestation.findBy(
ITEMS_SEARCHED_DEFAULT,
undefined,
{
subject: address,
},
"attestedDate",
(sortByDateDirection as OrderDirection) || "desc",
);
}),
)
: [];
Expand Down

0 comments on commit 19beba6

Please sign in to comment.