From 0f035d5d3a355dd6b262fa2ee740eb96dbdfbd41 Mon Sep 17 00:00:00 2001 From: Rohan Ahire <75326769+rohan-ahire06@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:21:33 +0530 Subject: [PATCH] fix: builders profile links -Disabled links and dimmed opacity for builders without profile pages, ensuring users aren't redirected to 404 pages. -Highlighted addresses of builders with completed profile pages, making it easy to spot active profiles. --- .../app/builders/_components/MembersList.tsx | 71 ++++++++++++++----- packages/nextjs/app/builders/page.tsx | 35 ++++----- 2 files changed, 66 insertions(+), 40 deletions(-) diff --git a/packages/nextjs/app/builders/_components/MembersList.tsx b/packages/nextjs/app/builders/_components/MembersList.tsx index f7d80f8..c985e9c 100644 --- a/packages/nextjs/app/builders/_components/MembersList.tsx +++ b/packages/nextjs/app/builders/_components/MembersList.tsx @@ -1,10 +1,19 @@ +"use client"; + import React from "react"; import Link from "next/link"; import { AiOutlineLoading3Quarters } from "react-icons/ai"; import { Address } from "~~/components/scaffold-eth"; -import { useScaffoldEventHistory } from "~~/hooks/scaffold-eth"; +import { useScaffoldEventHistory, useScaffoldReadContract } from "~~/hooks/scaffold-eth"; + +const MembersList = ({ builders }: { builders: string[] }) => { + // Getting the list of builders who have completed their check-in. + const { data: checkedInnBuilders, isLoading: loading } = useScaffoldReadContract({ + contractName: "BatchRegistry", + functionName: "checkedInCounter", + }); -const MembersList = () => { + // Getting the list of builders' address list who have completed their check-in. const { data: MembersList } = useScaffoldEventHistory({ contractName: "BatchRegistry", eventName: "CheckedIn", @@ -16,22 +25,50 @@ const MembersList = () => { console.log("list", MembersList); return ( -
- {!MembersList && ( -
- -
- )} - {MembersList?.map((member, i) => { - return ( - -
-
+ <> +
+

Builders :

+

+ {loading ? ( +

+
- - ); - })} -
+ ) : ( + checkedInnBuilders?.toString() + )} +

+
+ +
+ {!MembersList && ( +
+ +
+ )} + + {MembersList?.map((member, i) => { + const address = member?.args?.builder; + const isFileSystemAddress = address ? builders.includes(address) : false; + return ( + +
+
+
+ + ); + })} +
+ ); }; diff --git a/packages/nextjs/app/builders/page.tsx b/packages/nextjs/app/builders/page.tsx index 142915e..8453bb8 100644 --- a/packages/nextjs/app/builders/page.tsx +++ b/packages/nextjs/app/builders/page.tsx @@ -1,32 +1,21 @@ -"use client"; - import React from "react"; import MembersList from "./_components/MembersList"; -import { AiOutlineLoading3Quarters } from "react-icons/ai"; -import { useScaffoldReadContract } from "~~/hooks/scaffold-eth"; +import fs from "fs/promises"; +import path from "path"; + +// Getting teh buildres dir. data +const getBuildersData = async () => { + const buildersDirectory = path.join(process.cwd(), "/app/builders"); + const builderFiles = await fs.readdir(buildersDirectory); + return builderFiles.filter(file => file !== "page.tsx").map(file => file.replace(".tsx", "")); +}; -const BuildersPage = () => { - const { data: checkedInnBuilders, isLoading: loading } = useScaffoldReadContract({ - contractName: "BatchRegistry", - functionName: "checkedInCounter", - }); +const BuildersPage = async () => { + const builders = await getBuildersData(); return (

🏰 The Builders 🏗️ of BuidlGuidl: Batch #8

-
-

Builders :

-

- {loading ? ( -

- -
- ) : ( - checkedInnBuilders?.toString() - )} -

-
- - +
); };