Skip to content

Commit

Permalink
Showing Builders without profile on BuildersGrid; Removing the checke…
Browse files Browse the repository at this point in the history
…dInCount, it's supposed to be implemented on a different task
  • Loading branch information
melanke committed Dec 5, 2024
1 parent 5b62d7e commit 6530fbc
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions packages/nextjs/components/batch/BuildersGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import Link from "next/link";
import { useQuery } from "@tanstack/react-query";
import { Address } from "~~/components/scaffold-eth";
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";
import { useScaffoldEventHistory } 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<string[]>({
queryKey: ["builders-profiles"],
Expand All @@ -20,21 +14,28 @@ const BuildersGrid = () => {
},
});

if (countLoading || profilesLoading) {
// Get checked-in builders from contract events
const { data: events, isLoading: eventsLoading } = useScaffoldEventHistory({
contractName: "BatchRegistry",
eventName: "CheckedIn",
fromBlock: 127324219n,
});

if (profilesLoading || eventsLoading) {
return (
<div className="w-full px-6 py-8 text-center">
<span className="loading loading-spinner loading-lg text-primary"></span>
</div>
);
}

const buildersWithoutProfile = (events ?? [])
.map(event => event.args.builder)
.filter(address => address && !profileBuilders.includes(address));
console.log(buildersWithoutProfile);

return (
<div className="w-full px-6 py-8">
<div className="mb-6">
<h2 className="text-2xl font-bold mb-2">Batch Members ({checkedInCount?.toString() || "0"} checked in)</h2>
<p className="text-sm text-base-content/70">Showing builders who have created their profiles</p>
</div>

<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{profileBuilders.map((address, idx) => (
<Link
Expand All @@ -46,13 +47,23 @@ const BuildersGrid = () => {
<Address address={address} size="lg" />
<div className="flex justify-between items-center">
<span className="text-sm font-semibold hover:underline">View Profile →</span>
{checkedInCount && checkedInCount > 0 && (
<span className="text-xs bg-primary/10 px-2 py-1 rounded-full">Checked In</span>
)}
</div>
</div>
</Link>
))}
{buildersWithoutProfile.map((address, idx) => (
<div
key={`${address}-${idx}`}
className="bg-base-100 rounded-xl p-6 shadow-lg hover:shadow-xl transition-all duration-200 border border-base-200"
>
<div className="flex flex-col gap-2">
<Address address={address} size="lg" />
<div className="flex justify-between items-center">
<span className="text-sm font-semibold text-primary">No Profile</span>
</div>
</div>
</div>
))}
</div>
</div>
);
Expand Down

0 comments on commit 6530fbc

Please sign in to comment.