From 1c9d8626545085f905189d10948e3d5ade7cbf11 Mon Sep 17 00:00:00 2001 From: Anang Yusman Date: Fri, 4 Jul 2025 10:47:42 +0800 Subject: [PATCH] feat: update --- components/details/details-content.tsx | 66 +++++++++++++++++++++----- components/landing-page/header.tsx | 16 ++++++- 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/components/details/details-content.tsx b/components/details/details-content.tsx index 67c0ce4..515a5c0 100644 --- a/components/details/details-content.tsx +++ b/components/details/details-content.tsx @@ -71,28 +71,39 @@ export default function DetailContent() { }, [activeTab]); async function fetchTabArticles() { - const req = { - limit: "5", - page: 1, - search: "-", - categorySlug: "-", + const req: any = { + limit: showData, + page, + search, + categorySlug: Array.from(selectedCategories).join(","), sort: "desc", sortBy: "created_at", }; - try { - if (activeTab === "trending") { - req.sortBy = "view_count"; - } else if (activeTab === "comments") { - req.sortBy = "comment_count"; - } else { - req.sortBy = "created_at"; - } + // Sesuaikan sortBy berdasarkan tab + if (activeTab === "trending") { + req.sortBy = "view_count"; + } else if (activeTab === "comments") { + req.sortBy = "comment_count"; + } else { + req.sortBy = "created_at"; + } + // Hanya kirimkan search jika valid + if (search && search !== "-" && search !== "") { + req.search = search; + } + + if (selectedCategories && selectedCategories !== "-") { + req.categorySlug = selectedCategories; + } + + try { const res = await getListArticle(req); setTabArticles(res?.data?.data || []); } catch (error) { console.error("Failed fetching tab articles:", error); + setTabArticles([]); // Optional fallback } } @@ -536,6 +547,35 @@ export default function DetailContent() { ))} + {tabArticles.length === 0 ? ( +

+ Artikel tidak ditemukan. +

+ ) : ( + tabArticles.map((item, idx) => ( +
+ {item.title} +
+

+ {item.title} +

+

+ {new Date(item.createdAt).toLocaleDateString("id-ID", { + day: "2-digit", + month: "long", + year: "numeric", + })} +

+
+
+ )) + )}
diff --git a/components/landing-page/header.tsx b/components/landing-page/header.tsx index 77bd785..cf646bf 100644 --- a/components/landing-page/header.tsx +++ b/components/landing-page/header.tsx @@ -94,8 +94,22 @@ export default function HeroNewsSection() {

{articles[0].title}

-

+

{articles[0].createdByName} -{" "} + + + + + + {" "} {new Date(articles[0].createdAt).toLocaleDateString( "id-ID", {