From c9303e5aad64a148d403146a81fc9eba55baa99c Mon Sep 17 00:00:00 2001 From: "diana.dolgolyova" Date: Thu, 26 Mar 2026 12:16:56 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20news=20pagination=20=E2=80=94=20replace?= =?UTF-8?q?=20show=20more/collapse=20with=20page=20controls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/sections/News.tsx | 55 +++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/src/components/sections/News.tsx b/src/components/sections/News.tsx index e6ce631..7f004e8 100644 --- a/src/components/sections/News.tsx +++ b/src/components/sections/News.tsx @@ -121,11 +121,11 @@ function CompactArticle({ ); } -const INITIAL_VISIBLE = 4; +const PER_PAGE = 4; export function News({ data }: NewsProps) { const [selected, setSelected] = useState(null); - const [showAll, setShowAll] = useState(false); + const [page, setPage] = useState(0); if (!data.items || data.items.length === 0) return null; @@ -135,8 +135,8 @@ export function News({ data }: NewsProps) { .sort((a, b) => (b.date || "").localeCompare(a.date || "")); if (sorted.length === 0) return null; const [featured, ...rest] = sorted; - const visibleRest = showAll ? rest : rest.slice(0, INITIAL_VISIBLE - 1); - const hasMore = rest.length > INITIAL_VISIBLE - 1 && !showAll; + const totalPages = Math.max(1, Math.ceil(rest.length / PER_PAGE)); + const visibleRest = rest.slice(page * PER_PAGE, (page + 1) * PER_PAGE); return (
@@ -168,17 +168,48 @@ export function News({ data }: NewsProps) { )} - {hasMore && ( - -
+ {totalPages > 1 && ( +
+ + {Array.from({ length: totalPages }, (_, i) => ( -
- + ))} + +
)}