-
Notifications
You must be signed in to change notification settings - Fork 11
feat: implement batch members list page with subgraph integration #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yu-Oscar
wants to merge
2
commits into
BuidlGuidl:main
Choose a base branch
from
Yu-Oscar:batch-memeber-list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+226
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -57,5 +57,8 @@ | |
| }, | ||
| "engines": { | ||
| "node": ">=20.18.3" | ||
| }, | ||
| "dependencies": { | ||
| "graphql-request": "^7.3.5" | ||
| } | ||
| } | ||
This file contains hidden or 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,34 @@ | ||
| "use client"; | ||
|
|
||
| import { QueryClient, QueryClientProvider, isServer } from "@tanstack/react-query"; | ||
|
|
||
| // /app/QueryClientProvider.tsx | ||
| function makeQueryClient() { | ||
| return new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { | ||
| // With SSR, we usually want to set some default staleTime | ||
| // above 0 to avoid refetching immediately on the client | ||
| staleTime: 60 * 1000, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
| let browserQueryClient: QueryClient | undefined = undefined; | ||
| function getQueryClient() { | ||
| if (isServer) { | ||
| // Server: always make a new query client | ||
| return makeQueryClient(); | ||
| } else { | ||
| // Browser: make a new query client if we don't already have one | ||
| // This is very important, so we don't re-make a new client if React | ||
| // suspends during the initial render. This may not be needed if we | ||
| // have a suspense boundary BELOW the creation of the query client | ||
| if (!browserQueryClient) browserQueryClient = makeQueryClient(); | ||
| return browserQueryClient; | ||
| } | ||
| } | ||
| export default function Providers({ children }: Readonly<{ children: React.ReactNode }>) { | ||
| const queryClient = getQueryClient(); | ||
| return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>; | ||
| } |
This file contains hidden or 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,34 @@ | ||
| "use client"; | ||
|
|
||
| import { QueryClient, QueryClientProvider, isServer } from "@tanstack/react-query"; | ||
|
|
||
| // /app/QueryClientProvider.tsx | ||
| function makeQueryClient() { | ||
| return new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { | ||
| // With SSR, we usually want to set some default staleTime | ||
| // above 0 to avoid refetching immediately on the client | ||
| staleTime: 60 * 1000, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
| let browserQueryClient: QueryClient | undefined = undefined; | ||
| function getQueryClient() { | ||
| if (isServer) { | ||
| // Server: always make a new query client | ||
| return makeQueryClient(); | ||
| } else { | ||
| // Browser: make a new query client if we don't already have one | ||
| // This is very important, so we don't re-make a new client if React | ||
| // suspends during the initial render. This may not be needed if we | ||
| // have a suspense boundary BELOW the creation of the query client | ||
| if (!browserQueryClient) browserQueryClient = makeQueryClient(); | ||
| return browserQueryClient; | ||
| } | ||
| } | ||
| export default function Providers({ children }: Readonly<{ children: React.ReactNode }>) { | ||
| const queryClient = getQueryClient(); | ||
| return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>; | ||
| } |
This file contains hidden or 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,15 @@ | ||
| import BuildersList from "~~/components/BuildersList"; | ||
| import { getProcessedBuilders } from "~~/utils/builders"; | ||
|
|
||
| const BuildersPage = async () => { | ||
| const processedBuilders = await getProcessedBuilders(); | ||
|
|
||
| return ( | ||
| <div className="flex items-center flex-col grow pt-10"> | ||
| <h1 className="text-2xl font-bold mb-4">Builders List</h1> | ||
| <BuildersList builders={processedBuilders} /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default BuildersPage; |
This file contains hidden or 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 hidden or 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,38 @@ | ||
| "use client"; | ||
|
|
||
| import Link from "next/link"; | ||
| import { Address } from "@scaffold-ui/components"; | ||
| import { ProcessedBuilder } from "~~/utils/builders"; | ||
|
|
||
| type BuildersListProps = { | ||
| builders: ProcessedBuilder[]; | ||
| }; | ||
|
|
||
| const BuildersList = ({ builders }: BuildersListProps) => { | ||
| return ( | ||
| <div className="w-full max-w-4xl px-4"> | ||
| <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> | ||
| {builders.map(builder => ( | ||
| <div | ||
| key={`${builder.builder}`} | ||
| className="bg-base-100 border border-base-300 rounded-lg p-4 hover:shadow-[0_0_20px_rgba(255,255,255,0.2)] flex flex-col gap-2" | ||
| > | ||
| <Address | ||
| address={builder.builder as `0x${string}`} | ||
| format="short" | ||
| onlyEnsOrAddress={true} | ||
| disableAddressLink | ||
| /> | ||
| {builder.hasPage && builder.checksummedAddress && ( | ||
| <Link href={`/builders/${builder.checksummedAddress}`} className="btn btn-primary btn-sm mt-2"> | ||
| View Profile | ||
| </Link> | ||
| )} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default BuildersList; |
This file contains hidden or 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 hidden or 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 hidden or 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,60 @@ | ||
| import fs from "fs"; | ||
| import { gql, request } from "graphql-request"; | ||
| import path from "path"; | ||
|
|
||
| const GRAPHQL_QUERY = gql` | ||
| { | ||
| checkedIns { | ||
| builder | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const GRAPHQL_URL = "https://api.studio.thegraph.com/query/1717360/batch-22-buidlguidl/version/latest"; | ||
|
|
||
| export type ProcessedBuilder = { | ||
| builder: string; | ||
| index: number; | ||
| hasPage: boolean; | ||
| checksummedAddress: string | null; | ||
| }; | ||
|
|
||
| /** | ||
| * Fetches builders data from GraphQL, removes duplicates, reads builder pages from filesystem, | ||
| * and enriches each builder with page information. | ||
| * @returns Array of processed builders with page information | ||
| */ | ||
| export async function getProcessedBuilders(): Promise<ProcessedBuilder[]> { | ||
| // Fetch data from GraphQL | ||
| const data = await request(GRAPHQL_URL, GRAPHQL_QUERY, {}); | ||
| const checkedIns = (data?.checkedIns || []) as Array<{ builder: string }>; | ||
|
|
||
| // Remove duplicates | ||
| const uniqueBuilders = Array.from( | ||
| new Map(checkedIns.map((item, index) => [item.builder, { ...item, index }])).values(), | ||
| ) as Array<{ builder: string; index: number }>; | ||
|
|
||
| // Read folders from filesystem | ||
| const buildersDir = path.join(process.cwd(), "app/builders"); | ||
| const folders = fs | ||
| .readdirSync(buildersDir, { withFileTypes: true }) | ||
| .filter(dirent => dirent.isDirectory()) | ||
| .map(dirent => dirent.name); | ||
|
|
||
| // Create folder map (lowercase -> checksummed address) | ||
| const folderMap = new Map<string, string>(); | ||
| folders.forEach(folder => { | ||
| folderMap.set(folder.toLowerCase(), folder); | ||
| }); | ||
|
|
||
| // Enrich builders with page information | ||
| return uniqueBuilders.map(builder => { | ||
| const checksummedAddress = folderMap.get(builder.builder.toLowerCase()); | ||
| return { | ||
| builder: builder.builder, | ||
| index: builder.index, | ||
| hasPage: !!checksummedAddress, | ||
| checksummedAddress: checksummedAddress || null, | ||
| }; | ||
| }); | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.