Skip to content
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

Fetch and Display Builder Count from BatchRegistry Contract #17

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 83 additions & 4 deletions packages/nextjs/app/page.tsx
Superior212 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,10 +1,92 @@
"use client";

import { useEffect, useState } from "react";
import Link from "next/link";
import type { NextPage } from "next";
import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";

const Home: NextPage = () => {
const [counter, setCounter] = useState<number | undefined>();
Superior212 marked this conversation as resolved.
Show resolved Hide resolved

const {
data,
Superior212 marked this conversation as resolved.
Show resolved Hide resolved
error,
isLoading: contractLoading,
} = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "checkedInCounter",
});

useEffect(() => {
if (data !== undefined) {
setCounter(Number(data));
}
}, [data]);

const renderContent = () => {
Superior212 marked this conversation as resolved.
Show resolved Hide resolved
if (error) {
return (
<div className="p-4 rounded-lg bg-red-100 text-red-700" role="alert">
<p>Error fetching contract data: {error.message}</p>
</div>
);
}

return (
<p className="text-lg flex gap-2 justify-center">
<span className="font-bold">Checked in builders count:</span>
<span>{counter !== undefined ? counter : "0"}</span>
Superior212 marked this conversation as resolved.
Show resolved Hide resolved
</p>
);
};

if (contractLoading) {
return (
<div className="w-full h-full mt-20 animate-pulse">
<div className="mb-6 flex items-center">
<div className="w-10 h-10 bg-gray-200 rounded-full mr-4"></div>
<div>
<div className="h-4 bg-gray-200 rounded w-24 mb-2"></div>
<div className="h-6 bg-gray-200 rounded w-48"></div>
</div>
</div>

<div className="grid md:grid-cols-2 gap-8">
<div className="bg-gray-200 rounded-lg h-96"></div>

<div>
<div className="h-8 bg-gray-200 rounded w-3/4 mb-4"></div>
<div className="space-y-2 mb-6">
{[...Array(6)].map((_, index) => (
<div key={index} className="h-4 bg-gray-200 rounded w-full"></div>
))}
</div>

<div className="flex items-center mb-4">
<div className="h-8 bg-gray-200 rounded w-24 mr-4"></div>
<div className="h-8 bg-gray-200 rounded-full w-8"></div>
<div className="h-6 bg-gray-200 rounded w-8 mx-4"></div>
<div className="h-8 bg-gray-200 rounded-full w-8"></div>
</div>

<div className="flex space-x-4 mb-6">
<div className="h-10 bg-gray-200 rounded w-2/3"></div>
<div className="h-10 bg-gray-200 rounded w-1/3"></div>
</div>

<div>
<div className="h-6 bg-gray-200 rounded w-24 mb-2"></div>
<div className="h-4 bg-gray-200 rounded w-full mb-2"></div>
<div className="h-4 bg-gray-200 rounded w-full mb-2"></div>
<div className="h-4 bg-gray-200 rounded w-3/4"></div>
</div>
</div>
</div>
</div>
);
}
Superior212 marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
<div className="flex items-center flex-col flex-grow pt-10">
Expand All @@ -14,10 +96,7 @@ const Home: NextPage = () => {
<span className="block text-4xl font-bold">Batch 10</span>
</h1>
<p className="text-center text-lg">Get started by taking a look at your batch GitHub repository.</p>
<p className="text-lg flex gap-2 justify-center">
<span className="font-bold">Checked in builders count:</span>
<span>To Be Implemented</span>
</p>
{renderContent()}
</div>

<div className="flex-grow bg-base-300 w-full mt-16 px-8 py-12">
Expand Down
Loading