diff --git a/components/form/content/spit-convert-form.tsx b/components/form/content/spit-convert-form.tsx index b4abb55d..e376996e 100644 --- a/components/form/content/spit-convert-form.tsx +++ b/components/form/content/spit-convert-form.tsx @@ -91,7 +91,7 @@ interface Detail { contentThumbnail: string; contentTag: string; categoryId?: number; - contentList?: FileType[]; + contentList?: FileType[]; // keep as FileType[] } interface Option { @@ -99,11 +99,15 @@ interface Option { label: string; } +// Updated FileType to reflect API response interface FileType { contentId: number; - contentFile: string; - thumbnailFileUrl: string; - fileName: string; + contentFile: string; // URL + contentType: "IMAGE" | "VIDEO" | string; + contentFileRawType?: string; // e.g. video/mp4 or image/jpeg + contentFileName?: string | null; + thumbnailFileUrl?: string | null; + fileName?: string | null; } interface PlacementData { @@ -200,7 +204,9 @@ export default function FormConvertSPIT() { const [showRewriteEditor, setShowRewriteEditor] = useState(false); const [isGeneratingRewrite, setIsGeneratingRewrite] = useState(false); const [isLoadingRewrite, setIsLoadingRewrite] = useState(false); - const [detailThumb, setDetailThumb] = useState([]); + + // <-- changed: detailThumb is now FileType[] (objects from API) --> + const [detailThumb, setDetailThumb] = useState([]); const [thumbsSwiper, setThumbsSwiper] = useState(null); const [files, setFiles] = useState([]); const [filePlacements, setFilePlacements] = useState([]); @@ -220,13 +226,6 @@ export default function FormConvertSPIT() { initializeComponent(); }, []); - // useEffect(() => { - // const savedFlag = localStorage.getItem(`spit_saved_${id}`); - // if (savedFlag === "true") { - // setIsAlreadySaved(true); - // } - // }, [id]); - useEffect(() => { checkUserPermissions(); }, [userLevelId, roleId]); @@ -263,7 +262,6 @@ export default function FormConvertSPIT() { const categories = response?.data?.data?.content || []; setCategories(categories); - // Auto-select "Pers Rilis" category if schedule type is 3 const scheduleId = Cookies.get("scheduleId"); const scheduleType = Cookies.get("scheduleType"); @@ -305,15 +303,25 @@ export default function FormConvertSPIT() { } setDetail(details); - setFiles(details.contentList || []); - setDetailThumb( - (details.contentList || []).map( - (file: FileType) => file.contentFile || "default-image.jpg" - ) + + // <-- use API contentList objects directly --> + const contentList: FileType[] = (details.contentList || []).map( + (it: any) => ({ + contentId: it.contentId, + contentFile: it.contentFile, + contentType: it.contentType, + contentFileRawType: it.contentFileRawType, + contentFileName: it.contentFileName, + thumbnailFileUrl: it.thumbnailFileUrl || null, + fileName: it.contentFileName || null, + }) ); + setFiles(contentList); + setDetailThumb(contentList); + // Initialize file placements - const fileCount = details.contentList?.length || 0; + const fileCount = contentList.length || 0; setFilePlacements(Array(fileCount).fill([])); // Set form values @@ -322,7 +330,7 @@ export default function FormConvertSPIT() { setValue("contentCreator", details.contentCreator || ""); setValue( "contentRewriteDescription", - details.contentRewriteDescription || "" + (details as any).contentRewriteDescription || "" ); if (details.categoryId) { @@ -536,7 +544,7 @@ export default function FormConvertSPIT() { }; const getPlacementData = () => { - const placementData = []; + const placementData: PlacementData[] = []; console.log("filePlacements : ", filePlacements); for (let i = 0; i < filePlacements.length; i++) { if (filePlacements[i].length > 0) { @@ -613,17 +621,12 @@ export default function FormConvertSPIT() { await convertSPIT(requestData); - // localStorage.setItem(`spit_saved_${id}`, "true"); - // setIsAlreadySaved(true); - MySwal.fire({ title: "Success", text: "Data saved successfully", icon: "success", confirmButtonColor: "#3085d6", }).then(() => { - // router.push("/in/contributor/content/spit"); - // router.replace(`${window.location.pathname}?id=${id}`); loadDetail(); }); } catch (error) { @@ -932,13 +935,32 @@ export default function FormConvertSPIT() { navigation={true} className="w-full h-96" > - {detailThumb.map((image, index) => ( - - {`Media + {detailThumb.map((item) => ( + + {item.contentType === "VIDEO" ? ( +
+
+
+ {/* main video player */} +
+
+
+ ) : ( + {`Media + )}
))} @@ -950,13 +972,38 @@ export default function FormConvertSPIT() { modules={[Pagination, Thumbs]} className="w-full" > - {detailThumb.map((image, index) => ( - - {`Thumbnail + {detailThumb.map((item) => ( + + {item.contentType === "VIDEO" ? ( +
+ {/* use preload metadata so browser doesn't download full video */} +
+ ) : ( + {`Thumbnail + )}
))} @@ -1008,13 +1055,27 @@ export default function FormConvertSPIT() { key={file.contentId} className="flex gap-4 p-4 border rounded-lg" > - {file.fileName} + {/* show thumbnail or video preview */} + {file.contentType === "VIDEO" ? ( +