diff --git a/components/form/content/spit-convert-form.tsx b/components/form/content/spit-convert-form.tsx index 111b1e0d..50ca5c50 100644 --- a/components/form/content/spit-convert-form.tsx +++ b/components/form/content/spit-convert-form.tsx @@ -47,6 +47,7 @@ import { // Swiper import { Swiper, SwiperSlide } from "swiper/react"; +import { Swiper as SwiperType } from "swiper"; import "swiper/css"; import "swiper/css/free-mode"; import "swiper/css/navigation"; @@ -205,7 +206,7 @@ export default function FormConvertSPIT() { // <-- changed: detailThumb is now FileType[] (objects from API) --> const [detailThumb, setDetailThumb] = useState([]); - const [thumbsSwiper, setThumbsSwiper] = useState(null); + const [thumbsSwiper, setThumbsSwiper] = useState(null); const [files, setFiles] = useState([]); const [filePlacements, setFilePlacements] = useState([]); const [articleIds, setArticleIds] = useState([]); @@ -228,6 +229,13 @@ export default function FormConvertSPIT() { checkUserPermissions(); }, [userLevelId, roleId]); + // Handle Swiper re-initialization when detailThumb changes + useEffect(() => { + if (thumbsSwiper && detailThumb.length > 0) { + thumbsSwiper.update(); + } + }, [detailThumb, thumbsSwiper]); + const initializeComponent = async () => { try { setIsLoading(true); @@ -281,7 +289,10 @@ export default function FormConvertSPIT() { try { const response = await getTagsBySubCategoryId(categoryId); if (response?.data?.data?.length > 0) { - const tagsMerge = [...tags, response?.data?.data]; + // Extract tag names from the response objects + const apiTags = response?.data?.data?.map((tag: any) => tag.tagName); + // Merge with existing tags, ensuring uniqueness + const tagsMerge = Array.from(new Set([...tags, ...apiTags])); setTags(tagsMerge); } } catch (error) { @@ -331,16 +342,16 @@ export default function FormConvertSPIT() { (details as any).contentRewriteDescription || "" ); + // Set category and load category tags if (details.categoryId) { setSelectedCategoryId(details.categoryId); await loadTags(details.categoryId); } + // Set content tags and merge with category tags if (details.contentTag) { - const initialTags = details.contentTag - .split(",") - .map((tag: string) => tag.trim()); - setTags(initialTags); + const contentTags = details.contentTag.split(",").map((tag: string) => tag.trim()); + setTags(prev => Array.from(new Set([...prev, ...contentTags]))); } } catch (error) { console.error("Failed to load detail:", error); @@ -543,7 +554,6 @@ export default function FormConvertSPIT() { const getPlacementData = () => { const placementData: PlacementData[] = []; - console.log("filePlacements : ", filePlacements); for (let i = 0; i < filePlacements.length; i++) { if (filePlacements[i].length > 0) { const placements = filePlacements[i]; @@ -949,68 +959,114 @@ export default function FormConvertSPIT() { -
+
{detailThumb.map((item) => ( - + {item.contentType === "VIDEO" ? ( -
-
-
- {/* main video player */} -
-
+
+
) : ( - {`Media +
+ {`Media { + console.error('Image load error:', e); + e.currentTarget.style.display = 'none'; + }} + /> +
)} ))} {detailThumb.map((item) => ( - + {item.contentType === "VIDEO" ? ( -
+
{/* use preload metadata so browser doesn't download full video */}
) : ( - {`Thumbnail +
+ {`Thumbnail { + console.error('Thumbnail image load error:', e); + e.currentTarget.style.display = 'none'; + }} + /> +
)} ))}