From 02b3cc808437ee322132ddee8c2035f67b77af19 Mon Sep 17 00:00:00 2001 From: Jerry <62429807+Jerrys-C@users.noreply.github.com> Date: Thu, 5 Jun 2025 07:21:43 +0800 Subject: [PATCH 1/2] Implement pagination and transition effects in BrokenArtifacts component --- app/brokenArtifacts.tsx | 205 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 187 insertions(+), 18 deletions(-) diff --git a/app/brokenArtifacts.tsx b/app/brokenArtifacts.tsx index f89c1fe..457bafa 100644 --- a/app/brokenArtifacts.tsx +++ b/app/brokenArtifacts.tsx @@ -1,10 +1,13 @@ "use client"; -import { useMemo, useState } from "react"; +import { useMemo, useState, useEffect } from "react"; import artifactDb from "@/db.json"; const BrokenArtifacts = () => { const [searchQuery, setSearchQuery] = useState(""); + const [currentPage, setCurrentPage] = useState(1); + const [isTransitioning, setIsTransitioning] = useState(false); + const itemsPerPage = 10; const filteredArtifacts = useMemo(() => { return Object.entries(artifactDb.brokenArtifacts) @@ -26,9 +29,96 @@ const BrokenArtifacts = () => { }); }, [searchQuery]); + // Reset to first page when search changes + useMemo(() => { + setCurrentPage(1); + }, [searchQuery]); + + const totalPages = Math.ceil(filteredArtifacts.length / itemsPerPage); + const startIndex = (currentPage - 1) * itemsPerPage; + const endIndex = startIndex + itemsPerPage; + const currentArtifacts = filteredArtifacts.slice(startIndex, endIndex); + + const handlePageChange = (page: number) => { + if (page === currentPage || isTransitioning) return; + + setIsTransitioning(true); + + // Add a small delay to allow fade out animation + setTimeout(() => { + setCurrentPage(page); + // Reset transition state after content changes + setTimeout(() => { + setIsTransitioning(false); + }, 50); + }, 150); + }; + + const renderPaginationButtons = () => { + if (totalPages <= 1) return null; + + const buttons = []; + const maxVisiblePages = 5; + + let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2)); + let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1); + + if (endPage - startPage + 1 < maxVisiblePages) { + startPage = Math.max(1, endPage - maxVisiblePages + 1); + } + + // Previous button + if (currentPage > 1) { + buttons.push( + + ); + } + + // Page numbers + for (let i = startPage; i <= endPage; i++) { + buttons.push( + + ); + } + + // Next button + if (currentPage < totalPages) { + buttons.push( + + ); + } + + return buttons; + }; + return (
-
+ {/* Results summary */}
+ {searchQuery && (
+
+ {filteredArtifacts.length > 0
+ ? `Found ${filteredArtifacts.length} result${filteredArtifacts.length !== 1 ? 's' : ''}`
+ : 'No results found'
+ }
+
+ )}
+
+ {!searchQuery && filteredArtifacts.length > 0 && (
+
+ Showing {startIndex + 1}-{Math.min(endIndex, filteredArtifacts.length)} of {filteredArtifacts.length} artifacts
+
+ )}
+
+ {!filteredArtifacts.length && searchQuery ? (
+
+
+
OK
@@ -65,23 +171,86 @@ const BrokenArtifacts = () => {
{" "}
has not had any reported issues.
-
+
) : (
- filteredArtifacts.map(([key, value]) => (
-
+
-
-
- {key}
-
- {value}
-
+ {currentArtifacts.map(([key, value], index) => (
+
+
+
+ {key}
+
+
+ {value}
+
+
+
+ ))}
- ))
+
+ {/* Pagination */}
+ {totalPages > 1 && (
+
+ {renderPaginationButtons()}
+
+ )}
+
+ {/* Page info */}
+ {totalPages > 1 && (
+
+ Page {currentPage} of {totalPages}
+
+ )}
+ >
)}
+
+
);
};
From e7fb02a98ae92e26f72763390fe2e74ec918801d Mon Sep 17 00:00:00 2001
From: Jerry <62429807+Jerrys-C@users.noreply.github.com>
Date: Thu, 5 Jun 2025 07:52:35 +0800
Subject: [PATCH 2/2] Refactor BrokenArtifacts component: remove unused
useEffect import and change endPage variable to const
---
app/brokenArtifacts.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/brokenArtifacts.tsx b/app/brokenArtifacts.tsx
index 457bafa..0fbdab1 100644
--- a/app/brokenArtifacts.tsx
+++ b/app/brokenArtifacts.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useMemo, useState, useEffect } from "react";
+import { useMemo, useState } from "react";
import artifactDb from "@/db.json";
const BrokenArtifacts = () => {
@@ -61,7 +61,7 @@ const BrokenArtifacts = () => {
const maxVisiblePages = 5;
let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
- let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
+ const endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
if (endPage - startPage + 1 < maxVisiblePages) {
startPage = Math.max(1, endPage - maxVisiblePages + 1);