From cfc47a00a8d054f8ad66b553a32480e0b4ce827c Mon Sep 17 00:00:00 2001 From: Sabda Yagra Date: Fri, 1 Aug 2025 11:50:31 +0700 Subject: [PATCH] fix: fixing detail content and update content contributro --- app/[locale]/(public)/image/filter/page.tsx | 10 +- app/[locale]/(public)/video/filter/page.tsx | 8 +- components/form/content/image-update-form.tsx | 94 +++++++++++++++++-- components/main/image-detail.tsx | 2 +- 4 files changed, 98 insertions(+), 16 deletions(-) diff --git a/app/[locale]/(public)/image/filter/page.tsx b/app/[locale]/(public)/image/filter/page.tsx index 8af75edd..ef7777f5 100644 --- a/app/[locale]/(public)/image/filter/page.tsx +++ b/app/[locale]/(public)/image/filter/page.tsx @@ -823,7 +823,7 @@ const FilterPage = () => { {/* */}
- {/* { width: "100%", height: "100%", }} - /> */} - + {/* { image?.thumbnailLink } alt={image?.title} - className="w-full h-full object-cover rounded-t-lg" - /> + className="w-full h-full object-contain rounded-t-lg" + /> */}
{formatDateToIndonesian( diff --git a/app/[locale]/(public)/video/filter/page.tsx b/app/[locale]/(public)/video/filter/page.tsx index 3b7b0fae..a2b03dcb 100644 --- a/app/[locale]/(public)/video/filter/page.tsx +++ b/app/[locale]/(public)/video/filter/page.tsx @@ -833,7 +833,7 @@ const FilterPage = () => { {/* */}
- {/* { width: "100%", height: "100%", }} - /> */} - + {/* { } alt={video?.title} className="w-full h-full object-cover rounded-t-lg" - /> + /> */}
{formatDateToIndonesian( diff --git a/components/form/content/image-update-form.tsx b/components/form/content/image-update-form.tsx index 814bb4ce..dd64038b 100644 --- a/components/form/content/image-update-form.tsx +++ b/components/form/content/image-update-form.tsx @@ -166,7 +166,15 @@ export default function FormImageUpdate() { const { getRootProps, getInputProps } = useDropzone({ onDrop: (acceptedFiles) => { - setFiles(acceptedFiles.map((file) => Object.assign(file))); + // setFiles(acceptedFiles.map((file) => Object.assign(file))); + setFiles((prevFiles) => [ + ...prevFiles, + ...acceptedFiles.map((file) => + Object.assign(file, { + preview: URL.createObjectURL(file), + }) + ), + ]); }, accept: { "image/*": [], @@ -270,6 +278,19 @@ export default function FormImageUpdate() { setSelectedOptions(initialOptions); } + if (details?.files) { + const formattedFiles = details.files.map((file: any) => ({ + ...file, + id: file.id, + fileName: file.fileName, + size: file.size, + thumbnailFileUrl: file.thumbnailFileUrl, + url: file.url, + })); + + setFiles(formattedFiles); + } + if (details?.publishedFor) { // Split string "7" to an array ["7"] if needed setPublishedFor(details.publishedFor.split(",")); @@ -503,15 +524,41 @@ export default function FormImageUpdate() { setFiles([]); }; - const renderFilePreview = (file: FileWithPreview) => { - if (file?.type?.startsWith("image")) { + // const renderFilePreview = (file: FileWithPreview) => { + // if (file?.type?.startsWith("image")) { + // return ( + // {file.name} + // ); + // } else { + // return ; + // } + // }; + + const renderFilePreview = (file: FileWithPreview | any) => { + if (file?.preview || file instanceof File) { return ( {file.name} + ); + } else if (file.thumbnailFileUrl) { + return ( + {file.fileName} ); } else { @@ -525,9 +572,44 @@ export default function FormImageUpdate() { setFiles([...filtered]); }; + // const fileList = files.map((file: any) => ( + //
+ //
+ //
{renderFilePreview(file)}
+ //
+ //
+ // {file.fileName || file.name} + //
+ //
+ // {Math.round(file.size / 100) / 10 > 1000 ? ( + // <>{(Math.round(file.size / 100) / 10000).toFixed(1)} + // ) : ( + // <>{(Math.round(file.size / 100) / 10).toFixed(1)} + // )} + // {" kb"} + //
+ //
+ //
+ + // + //
+ // )); + const fileList = files.map((file: any) => (
diff --git a/components/main/image-detail.tsx b/components/main/image-detail.tsx index cd67a3c2..a42ddc01 100644 --- a/components/main/image-detail.tsx +++ b/components/main/image-detail.tsx @@ -537,7 +537,7 @@ const DetailImage = (data: any) => { height={1440} src={detailDataImage?.files[selectedImage]?.url} alt="Main" - className="rounded-lg h-[300px] w-screen lg:h-[600px] lg:w-[900px] object-cover" + className="rounded-lg h-[300px] w-screen lg:h-[600px] lg:w-full object-contain" />