-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from ludmila-omlopes/issue7
New "builders" page, with new Header link and json reference file.
- Loading branch information
Showing
4 changed files
with
115 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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() && dirent.name.startsWith("0x")); | ||
|
||
return NextResponse.json(addresses.map(dirent => dirent.name)); | ||
} catch (error) { | ||
console.error("Error reading builders directory:", error); | ||
return NextResponse.json({ error: "Failed to fetch builders" }, { status: 500 }); | ||
} | ||
} |
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,92 @@ | ||
"use client"; | ||
|
||
import { useEffect, useMemo, useState } from "react"; | ||
import { HiOutlineUserCircle } from "react-icons/hi"; | ||
import { Address } from "~~/components/scaffold-eth"; | ||
import { useScaffoldEventHistory } from "~~/hooks/scaffold-eth"; | ||
|
||
const BuildersPage = () => { | ||
const [validProfiles, setValidProfiles] = useState<string[]>([]); | ||
const { data: events, isLoading } = useScaffoldEventHistory({ | ||
contractName: "BatchRegistry", | ||
eventName: "CheckedIn", | ||
fromBlock: 130068488n, | ||
watch: true, | ||
}); | ||
|
||
const uniqueBuilders = useMemo(() => { | ||
return Array.from(new Set(events?.map(event => event.args.builder).filter(Boolean) || [])) as string[]; | ||
}, [events]); | ||
|
||
const sortedBuilders = useMemo(() => { | ||
return [...uniqueBuilders].sort((a, b) => { | ||
const aHasProfile = validProfiles.includes(a) ? 1 : 0; | ||
const bHasProfile = validProfiles.includes(b) ? 1 : 0; | ||
return bHasProfile - aHasProfile; | ||
}); | ||
}, [uniqueBuilders, validProfiles]); | ||
|
||
useEffect(() => { | ||
const checkProfiles = async () => { | ||
try { | ||
const response = await fetch("/api/builders"); | ||
if (!response.ok) { | ||
throw new Error("Failed to fetch builder profiles"); | ||
} | ||
const profiles = await response.json(); | ||
setValidProfiles(profiles); | ||
} catch (error) { | ||
console.error("Error checking builder profiles:", error); | ||
setValidProfiles([]); | ||
} | ||
}; | ||
|
||
if (uniqueBuilders.length > 0) { | ||
checkProfiles(); | ||
} | ||
}, [uniqueBuilders]); | ||
|
||
if (isLoading) { | ||
return ( | ||
<div className="min-h-screen flex justify-center items-center"> | ||
<div className="text-lg font-medium">Loading builders...</div> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="min-h-screen flex flex-col items-center"> | ||
<div className="w-full max-w-4xl bg-base-100 shadow-lg rounded-[22px] p-6 mt-10"> | ||
<h1 className="text-3xl font-bold mb-4">Builders in Batch 12</h1> | ||
<p className="mb-6"> | ||
Welcome to the list of builders who have successfully checked in for Batch 12. Below, you will find a list of | ||
all builders and their Ethereum addresses. If a builder has a profile page, you'll see a{" "} | ||
<HiOutlineUserCircle className="text-blue-600 dark:text-blue-400 inline w-6 h-6" /> icon next to their | ||
address. | ||
</p> | ||
<div className="gap-3 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3"> | ||
{sortedBuilders.map(builder => ( | ||
<div key={builder} className="bg-base-200 rounded-[22px] py-2 px-2 hover:bg-base-300 transition-all h-full"> | ||
<div className="flex justify-between items-center h-full"> | ||
<div> | ||
<Address address={builder} /> | ||
</div> | ||
{builder && validProfiles.includes(builder) && ( | ||
<a | ||
href={`/builders/${builder}`} | ||
className="text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300" | ||
title="View Profile" | ||
> | ||
<HiOutlineUserCircle className="w-6 h-6" /> | ||
</a> | ||
)} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BuildersPage; |
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