Skip to content

Commit

Permalink
Adjust batch table (removed github links, upcoming batch), added next…
Browse files Browse the repository at this point in the history
… starting to batch banner (#61)
  • Loading branch information
phipsae authored Jan 3, 2025
1 parent 65969ae commit 73adff4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/nextjs/pages/batches/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function getBatchNumber(batchName: string): number {
interface PageProps {
batchData: BatchData[];
openBatchNumber: number | null;
openBatchStartDate: number | null;
}

const formatDate = (timestamp: number): string => {
Expand Down Expand Up @@ -62,18 +63,20 @@ const BatchesHeader = () => {
);
};

const Batches = ({ batchData, openBatchNumber }: PageProps) => {
const Batches = ({ batchData, openBatchNumber, openBatchStartDate }: PageProps) => {
const [currentPage, setCurrentPage] = useState(1);
const itemsPerPage = 10;

const filteredBatchData = batchData.filter(batch => batch.status === "closed");

// Calculate pagination
const indexOfLastItem = currentPage * itemsPerPage;
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
const currentItems = batchData.slice(indexOfFirstItem, indexOfLastItem);
const currentItems = filteredBatchData.slice(indexOfFirstItem, indexOfLastItem);

const paginate = (pageNumber: number) => setCurrentPage(pageNumber);

const totalPages = Math.ceil(batchData.length / itemsPerPage);
const totalPages = Math.ceil(filteredBatchData.length / itemsPerPage);

return (
<>
Expand Down Expand Up @@ -176,7 +179,8 @@ const Batches = ({ batchData, openBatchNumber }: PageProps) => {
Batch #{openBatchNumber}
</h3>
<p className="text-white pr-2">
Complete SpeedRunEthereum and join BuidlGuidl to participate in the next Batch!
Complete SpeedRunEthereum and join BuidlGuidl to be part of the next batch starting
<strong>{openBatchStartDate ? ` on ${formatDate(openBatchStartDate)}` : "soon"}!</strong>
</p>
</div>
<div className="flex justify-center lg:justify-end w-full lg:w-auto">
Expand Down Expand Up @@ -230,13 +234,6 @@ const Batches = ({ batchData, openBatchNumber }: PageProps) => {
Website
</TrackedLink>
<div className="flex items-center gap-1">
<TrackedLink
id={`${batch.name}-github`}
href={batch.githubRepoLink || ""}
className="btn btn-xs btn-ghost p-0 min-h-0 w-[24px] h-[24px] hover:opacity-80 flex items-center justify-center"
>
<Image src="/assets/github-logo.png" alt="GitHub" width={24} height={24} />
</TrackedLink>
{batch.nftContractAddress && batch.graduates > 0 && (
<TrackedLink
id={`${batch.name}-opensea`}
Expand Down Expand Up @@ -292,13 +289,16 @@ export const getStaticProps: GetStaticProps<PageProps> = async () => {
// Find open batch number or calculate next batch number
const openBatch = batchesData.find(batch => batch.status === "open");
let openBatchNumber: number | null = null;
let openBatchStartDate: number | null = null;

if (openBatch) {
openBatchNumber = parseInt(openBatch.name);
openBatchStartDate = openBatch.startDate;
} else {
// Find the highest batch number and add 1
const highestBatch = Math.max(...batchesData.map(batch => parseInt(batch.name)));
openBatchNumber = highestBatch + 1;
openBatchStartDate = null;
}

// Enrich batch data with additional fields
Expand All @@ -318,6 +318,7 @@ export const getStaticProps: GetStaticProps<PageProps> = async () => {
props: {
batchData: sortedBatches,
openBatchNumber: openBatchNumber,
openBatchStartDate,
},
// 6 hours refresh
revalidate: 21600,
Expand All @@ -328,6 +329,7 @@ export const getStaticProps: GetStaticProps<PageProps> = async () => {
props: {
batchData: [],
openBatchNumber: null,
openBatchStartDate: null,
},
revalidate: 21600,
};
Expand Down

0 comments on commit 73adff4

Please sign in to comment.