From bbee46670776f9ec59c5c4d150d7fa107aabcc46 Mon Sep 17 00:00:00 2001 From: Colin Slater Date: Mon, 3 Feb 2025 17:22:05 -0800 Subject: [PATCH] Add collection list pager. --- app/_components/listPager.js | 70 ++++++++++++++++++++++++++++++++++++ app/page.js | 43 +++------------------- 2 files changed, 74 insertions(+), 39 deletions(-) create mode 100644 app/_components/listPager.js diff --git a/app/_components/listPager.js b/app/_components/listPager.js new file mode 100644 index 0000000..80bf72d --- /dev/null +++ b/app/_components/listPager.js @@ -0,0 +1,70 @@ + + +'use client' + +import Link from 'next/link' +import React from 'react'; +import { useState } from 'react' + +export default function ListPager({listEntries, entriesPerPage = 10}) { + + const [currentPage, setCurrentPage] = useState(1) + + const totalPages = () => { + return Math.ceil(listEntries.length/entriesPerPage) + } + + const previousPage = () => { + if(currentPage > 1) { + setCurrentPage(currentPage - 1) + } + } + + const nextPage = () => { + if(currentPage < totalPages()) { + setCurrentPage(currentPage + 1) + } + } + + const getSlice = (currentPage) => { + + return listEntries.slice((currentPage - 1) * entriesPerPage, currentPage * entriesPerPage) + } + const cellClassNames = "px-2 py-3" + + return ( +
+
+ + + + + + + + + + {getSlice(currentPage).map((summary, n) => + ( + + + ))} + +
CollectionRepoLast Updated
{summary.collection}{summary.repo}{summary.lastModified.toDateString()}
+ +
+
+ { currentPage > 1 ? : +
Prev
} +
+
Page {currentPage}/{totalPages()}
+
+ { currentPage < totalPages() ? : +
Next
} +
+
+
+
+ ) + +} diff --git a/app/page.js b/app/page.js index f29a6fe..6515a6e 100644 --- a/app/page.js +++ b/app/page.js @@ -2,6 +2,7 @@ import Link from 'next/link' import {ListSummaries, GetSummary, ListReports} from '@/lib/summaries' +import ListPager from '@/components/listPager' export const revalidate = 60 @@ -22,10 +23,6 @@ export default async function Collections() { return decodeURIComponent(uriEncodedCollection) } - /* - const reportFilenames = await ListReports() - const reports = reportFilenames.map(decodeReportFilename) - */ const cellClassNames = "px-2 py-3" @@ -41,44 +38,12 @@ export default async function Collections() {
-
- - - - - - - - - - {officialSummaryRefs.map((summary, n) => - ( - - - ))} - -
CollectionRepoLast Updated
{summary.collection}{summary.repo}{summary.lastModified.toDateString()}
-
+

User Collections

-
- - - - - - - - - - {userSummaryRefs.map((summary, n) => - ( - - - ))} - -
CollectionRepoLast Updated
{summary.collection}{summary.repo}{summary.lastModified.toDateString()}
+
+