From 78497bfcb11d249643705ea6eb79503b7aa38566 Mon Sep 17 00:00:00 2001 From: hanif salafi Date: Wed, 10 Sep 2025 12:05:12 +0700 Subject: [PATCH] feat: update fixing glitch swiper spit --- components/form/content/spit-convert-form.tsx | 142 +++++++++++++----- 1 file changed, 102 insertions(+), 40 deletions(-) diff --git a/components/form/content/spit-convert-form.tsx b/components/form/content/spit-convert-form.tsx index 3d87fdf2..05ecb648 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"; @@ -206,7 +207,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([]); @@ -229,6 +230,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); @@ -282,7 +290,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) { @@ -332,16 +343,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); @@ -544,7 +555,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]; @@ -950,68 +960,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'; + }} + /> +
)} ))}