-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: As a user, I want to be able to see the list of modules on Expl…
- Loading branch information
1 parent
2b9ac68
commit 0b8ad3f
Showing
18 changed files
with
208 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
import { ChevronLeft } from "lucide-react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useLocation, useNavigate } from "react-router-dom"; | ||
|
||
import { EMPTY_STRING } from "@/constants"; | ||
|
||
export interface BackProps { | ||
interface BackProps { | ||
className?: string; | ||
} | ||
|
||
export const Back: React.FC<BackProps> = ({ className }) => { | ||
const navigate = useNavigate(); | ||
const { state, pathname } = useLocation(); | ||
const backPath = pathname.split("/").slice(0, -1); | ||
const { title, handler } = state?.from | ||
? { handler: () => navigate(-1), title: "Back" } | ||
: { handler: () => navigate(backPath.join("/")), title: `Back to ${backPath.slice(-1)}` }; | ||
return ( | ||
<button | ||
onClick={() => navigate(-1)} | ||
onClick={() => handler()} | ||
className={`w-fit flex gap-2 text-text-tertiary hover:opacity-60 ${className || EMPTY_STRING}`} | ||
> | ||
<ChevronLeft width={24} height={24} /> | ||
Back | ||
{title} | ||
</button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export interface IPaginationProps { | ||
itemsCount: number; | ||
handleSkip: React.Dispatch<React.SetStateAction<number>>; | ||
handlePage: (page: number) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { ColumnDef } from "@tanstack/react-table"; | ||
import { Module } from "@verax-attestation-registry/verax-sdk"; | ||
|
||
import { HelperIndicator } from "@/components/HelperIndicator"; | ||
import { Link } from "@/components/Link"; | ||
import { toModuleById } from "@/routes/constants"; | ||
import { cropString } from "@/utils/stringUtils"; | ||
|
||
import { links } from "../index"; | ||
|
||
export const columns = (): ColumnDef<Module>[] => [ | ||
{ | ||
accessorKey: "id", | ||
header: () => "ID", | ||
cell: ({ row }) => { | ||
const id = row.getValue("id") as string; | ||
return ( | ||
<Link to={toModuleById(id)} className="hover:underline hover:text-text-quaternary"> | ||
{cropString(id)} | ||
</Link> | ||
); | ||
}, | ||
}, | ||
{ | ||
accessorKey: "name", | ||
header: () => ( | ||
<div className="flex items-center gap-2.5"> | ||
<HelperIndicator type="module" /> | ||
Module Name | ||
</div> | ||
), | ||
cell: ({ row }) => { | ||
const name = row.getValue("name") as string; | ||
return name; | ||
}, | ||
}, | ||
{ | ||
accessorKey: "description", | ||
header: () => "Module Description", | ||
cell: ({ row }) => { | ||
const description = row.getValue("description"); | ||
return <p className="max-w-[400px] overflow-hidden text-ellipsis">{description as string}</p>; | ||
}, | ||
}, | ||
{ | ||
accessorKey: "moduleAddress", | ||
header: () => <p className="text-right">Contract Address</p>, | ||
cell: ({ row }) => { | ||
const address = row.getValue("moduleAddress") as string; | ||
return ( | ||
<a | ||
href={`${links.lineascan.address}/${address}`} | ||
target="_blank" | ||
className="hover:underline hover:text-text-quaternary" | ||
> | ||
{cropString(address)} | ||
</a> | ||
); | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useState } from "react"; | ||
import useSWR from "swr"; | ||
|
||
import { DataTable } from "@/components/DataTable"; | ||
import { Pagination } from "@/components/Pagination"; | ||
import { ITEMS_PER_PAGE_DEFAULT, ZERO } from "@/constants"; | ||
import { columns } from "@/constants/columns/module"; | ||
import { SWRKeys } from "@/interfaces/swr/enum"; | ||
import { useNetworkContext } from "@/providers/network-provider/context"; | ||
import { getItemsByPage, pageBySearchParams } from "@/utils/paginationUtils"; | ||
|
||
export const Modules: React.FC = () => { | ||
const { | ||
sdk, | ||
network: { chain }, | ||
} = useNetworkContext(); | ||
const { data: modulesCount } = useSWR( | ||
`${SWRKeys.GET_MODULE_COUNT}/${chain.id}`, | ||
() => sdk.module.getModulesNumber() as Promise<bigint>, | ||
); | ||
|
||
const totalItems = modulesCount ? Number(modulesCount) : ZERO; | ||
const searchParams = new URLSearchParams(window.location.search); | ||
const page = pageBySearchParams(searchParams, totalItems); | ||
|
||
const [skip, setSkip] = useState<number>(getItemsByPage(page)); | ||
|
||
const { data: modulesList } = useSWR(`${SWRKeys.GET_MODULE_LIST}/${skip}/${chain.id}`, () => | ||
sdk.module.findBy(ITEMS_PER_PAGE_DEFAULT, skip), | ||
); | ||
|
||
const handlePage = (retrievedPage: number) => { | ||
setSkip(getItemsByPage(retrievedPage)); | ||
}; | ||
|
||
return ( | ||
<div className="container mt-5 md:mt-8"> | ||
<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 zinc-950">Explore Modules</h1> | ||
</div> | ||
<div> | ||
{/* TODO: add skeleton for table */} | ||
{modulesList && <DataTable columns={columns()} data={modulesList} />} | ||
{Boolean(modulesCount) && <Pagination itemsCount={totalItems} handlePage={handlePage} />} | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.