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} +
++ {new Date(item.createdAt).toLocaleDateString("id-ID", { + day: "2-digit", + month: "long", + year: "numeric", + })} +
++
{articles[0].createdByName} -{" "} + {" "} {new Date(articles[0].createdAt).toLocaleDateString( "id-ID", {