fix: media update section

This commit is contained in:
Sabda Yagra 2025-10-12 23:46:38 +07:00
parent fa36954d32
commit ff2bdebb03
1 changed files with 30 additions and 28 deletions

View File

@ -37,9 +37,9 @@ function formatTanggal(dateString: string) {
export default function MediaUpdate() {
const [tab, setTab] = useState<"latest" | "popular">("latest");
const [contentType, setContentType] = useState<
const [contentType, setContentType] = useState<
"audiovisual" | "audio" | "foto" | "text" | "all"
>("foto");
>("foto");
const [dataToRender, setDataToRender] = useState<any[]>([]);
const [filteredData, setFilteredData] = useState<any[]>([]);
const [bookmarkedIds, setBookmarkedIds] = useState<Set<number>>(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"));
@ -457,9 +461,7 @@ const [contentType, setContentType] = useState<
{/* Lihat lebih banyak - hanya muncul jika ada data */}
{filteredData.length > 0 && (
<div className="text-center mt-10">
<Link
href={getContentTypeLink()}
>
<Link href={getContentTypeLink()}>
<Button
size={"lg"}
className="text-[#b3882e] bg-transparent border border-[#b3882e] px-6 py-2 rounded-s-sm text-sm font-medium hover:bg-[#b3882e]/10 transition"