Skip to content

Commit

Permalink
feat(explorer): As a user, I want the Subject Page title to be explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
alainncls committed Nov 25, 2024
1 parent 3087119 commit 14c40a5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
9 changes: 9 additions & 0 deletions explorer/src/components/Title/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const Title = ({ title }: { title: string }) => {
return (
<div className="flex flex-col md:flex-row items-start md:items-center justify-between mb-6 md:mb-8 gap-6 md:gap-0">
<h1 className="text-2xl md:text-[2rem]/[2rem] font-semibold tracking-tighter text-text-primary dark:text-whiteDefault">
{title}
</h1>
</div>
);
};
39 changes: 38 additions & 1 deletion explorer/src/pages/Subject/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { OrderDirection } from "@verax-attestation-registry/verax-sdk/lib/types/.graphclient";
import { Check, Copy } from "lucide-react";
import { useState } from "react";
import { CopyToClipboard } from "react-copy-to-clipboard";
import { useParams } from "react-router-dom";
import useSWR from "swr";
import { isAddress } from "viem";

import { Title } from "@/components/Title";
import { THOUSAND } from "@/constants";
import { EQueryParams } from "@/enums/queryParams";
import useWindowDimensions from "@/hooks/useWindowDimensions.ts";
import { SWRKeys } from "@/interfaces/swr/enum";
import { useNetworkContext } from "@/providers/network-provider/context";
import { cropString } from "@/utils/stringUtils.ts";

import { CardView } from "../Attestations/components/CardView";

Expand All @@ -17,6 +25,20 @@ export const Subject: React.FC = () => {
const searchParams = new URLSearchParams(window.location.search);
const sortByDateDirection = searchParams.get(EQueryParams.SORT_BY_DATE);

const { sm } = useWindowDimensions();

const [copied, setCopied] = useState<boolean>(false);

const handleCopy = (text: string, result: boolean) => {
if (!result || !text) return;
setCopied(true);
setTimeout(() => {
setCopied(false);
}, THOUSAND);
};

const CopyIcon = copied ? Check : Copy;

const { data: attestationsList } = useSWR(
`${SWRKeys.GET_ATTESTATION_LIST}/${subject}/${sortByDateDirection}/${chain.id}`,
() =>
Expand All @@ -29,5 +51,20 @@ export const Subject: React.FC = () => {
),
);

return attestationsList && <CardView attestationsList={attestationsList}></CardView>;
return (
<div className="container mt-5 md:mt-8">
<Title title={"Explore Attestations"} />
<div className="flex items-center text-text-secondary dark:text-text-secondaryDark text-base font-medium gap-3 mb-6">
<div>With subject {sm && subject && isAddress(subject) ? cropString(subject) : subject}</div>
<CopyToClipboard onCopy={handleCopy} text={subject ?? ""}>
<CopyIcon
className={`w-4 cursor-pointer hover:opacity-60 transition ${
copied ? "text-greenDefault dark:text-greenDark" : "text-greyDefault dark:text-text-secondaryDark"
} `}
/>
</CopyToClipboard>
</div>
{attestationsList && <CardView attestationsList={attestationsList}></CardView>}
</div>
);
};

0 comments on commit 14c40a5

Please sign in to comment.