From ff2bdebb03eca69f5b17aa6d49fcf52663e090d1 Mon Sep 17 00:00:00 2001 From: Sabda Yagra Date: Sun, 12 Oct 2025 23:46:38 +0700 Subject: [PATCH] fix: media update section --- components/landing-page/media-update.tsx | 58 ++++++++++++------------ 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/components/landing-page/media-update.tsx b/components/landing-page/media-update.tsx index f7ebaca..6a8e481 100644 --- a/components/landing-page/media-update.tsx +++ b/components/landing-page/media-update.tsx @@ -37,9 +37,9 @@ function formatTanggal(dateString: string) { export default function MediaUpdate() { const [tab, setTab] = useState<"latest" | "popular">("latest"); -const [contentType, setContentType] = useState< - "audiovisual" | "audio" | "foto" | "text" | "all" ->("foto"); + const [contentType, setContentType] = useState< + "audiovisual" | "audio" | "foto" | "text" | "all" + >("foto"); const [dataToRender, setDataToRender] = useState([]); const [filteredData, setFilteredData] = useState([]); const [bookmarkedIds, setBookmarkedIds] = useState>(new Set()); @@ -128,7 +128,8 @@ const [contentType, setContentType] = useState< // Determine content type based on item properties const hasVideo = item.videoUrl || item.videoPath; const hasAudio = item.audioUrl || item.audioPath; - const hasImage = item.smallThumbnailLink || item.thumbnailUrl || item.imageUrl; + const hasImage = + item.smallThumbnailLink || item.thumbnailUrl || item.imageUrl; const hasText = item.content || item.description; switch (contentType) { @@ -152,15 +153,15 @@ const [contentType, setContentType] = useState< try { setLoading(true); - // Determine typeId based on contentType + // Tentukan typeId dari contentType const typeId = parseInt(getTypeIdByContentType(contentType)); setCurrentTypeId(typeId.toString()); - // 🔹 Ambil data artikel + // 🔹 Ambil data artikel dari API const response = await listArticles( 1, 10, - typeId, // Dynamic typeId based on content type + typeId, undefined, undefined, section === "latest" ? "createdAt" : "viewCount", @@ -177,18 +178,18 @@ const [contentType, setContentType] = useState< "", 20, 0, - // urutan === "latest" ? "createdAt" : "clickCount", "", "", "" ); - // hasil = fallback?.data?.data?.content || []; + hasil = fallbackRes?.data?.data?.content || []; } else { + // ✅ Perhatikan: API kamu mengembalikan `data.data` sebagai array hasil = response?.data?.data || []; } // 🔹 Normalisasi struktur data - let transformedData = hasil.map((article: any) => ({ + const transformedData = hasil.map((article: any) => ({ id: article.id, title: article.title, category: @@ -198,10 +199,13 @@ const [contentType, setContentType] = useState< createdAt: article.createdAt, smallThumbnailLink: article.thumbnailUrl, label: article.categoryName, + clientName: article.clientName, + typeId: article.typeId, ...article, })); - // setDataKonten(dataBaru); + // ✅ INI WAJIB: simpan hasil mapping ke state + setDataToRender(transformedData); // 🔹 Sinkronisasi data bookmark const roleId = Number(getCookiesDecrypt("urie")); @@ -302,8 +306,8 @@ const [contentType, setContentType] = useState< */} - +