diff --git a/app/brokenArtifacts.tsx b/app/brokenArtifacts.tsx index f89c1fe..0fbdab1 100644 --- a/app/brokenArtifacts.tsx +++ b/app/brokenArtifacts.tsx @@ -5,6 +5,9 @@ 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)); + const 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 (
-
+
@@ -52,10 +142,26 @@ const BrokenArtifacts = () => { />
- {!filteredArtifacts.length ? ( -
- - + {/* 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} +
+ )} + )} + +
); };