diff --git a/packages/nextjs/app/api/builders/route.ts b/packages/nextjs/app/api/builders/route.ts new file mode 100644 index 0000000..977f15b --- /dev/null +++ b/packages/nextjs/app/api/builders/route.ts @@ -0,0 +1,19 @@ +import { NextResponse } from "next/server"; +import { readdir } from "fs/promises"; +import path from "path"; + +export async function GET() { + const buildersPath = path.join(process.cwd(), "app/builders"); + + try { + const directories = await readdir(buildersPath, { withFileTypes: true }); + const addresses = directories + .filter(dirent => dirent.isDirectory()) + .map(dirent => dirent.name) + .filter(name => name.startsWith("0x")); + + return NextResponse.json(addresses); + } catch { + return NextResponse.json([], { status: 500 }); + } +} diff --git a/packages/nextjs/app/page.tsx b/packages/nextjs/app/page.tsx index a0a413f..ec2b3f9 100644 --- a/packages/nextjs/app/page.tsx +++ b/packages/nextjs/app/page.tsx @@ -3,6 +3,7 @@ import Link from "next/link"; import type { NextPage } from "next"; import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; +import BuildersGrid from "~~/components/batch/BuildersGrid"; const Home: NextPage = () => { return ( @@ -44,6 +45,8 @@ const Home: NextPage = () => { + {/* Builders Grid */} + > ); diff --git a/packages/nextjs/components/batch/BuildersGrid.tsx b/packages/nextjs/components/batch/BuildersGrid.tsx new file mode 100644 index 0000000..0088700 --- /dev/null +++ b/packages/nextjs/components/batch/BuildersGrid.tsx @@ -0,0 +1,61 @@ +import Link from "next/link"; +import { useQuery } from "@tanstack/react-query"; +import { Address } from "~~/components/scaffold-eth"; +import { useScaffoldReadContract } from "~~/hooks/scaffold-eth"; + +const BuildersGrid = () => { + // Get total number of checked-in builders from contract + const { data: checkedInCount, isLoading: countLoading } = useScaffoldReadContract({ + contractName: "BatchRegistry", + functionName: "checkedInCounter", + }); + + // Get builder profiles from filesystem + const { data: profileBuilders = [], isLoading: profilesLoading } = useQuery({ + queryKey: ["builders-profiles"], + queryFn: async () => { + const response = await fetch("/api/builders"); + if (!response.ok) throw new Error("Failed to fetch builders"); + return response.json(); + }, + }); + + if (countLoading || profilesLoading) { + return ( + + + + ); + } + + return ( + + + Batch Members ({checkedInCount?.toString() || "0"} checked in) + Showing builders who have created their profiles + + + + {profileBuilders.map((address, idx) => ( + + + + + View Profile → + {checkedInCount && checkedInCount > 0 && ( + Checked In + )} + + + + ))} + + + ); +}; + +export default BuildersGrid;
Showing builders who have created their profiles