From 168af3bf95458dd7e5af1ff8476d9a13f8a206e9 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Wed, 1 Jul 2026 11:23:11 +0330 Subject: [PATCH] pages video fix --- src/components/VideoUploadZone.tsx | 56 +++++++++++++------ .../sidebar/instructions/VideoInput.tsx | 54 ++++++++++-------- 2 files changed, 71 insertions(+), 39 deletions(-) diff --git a/src/components/VideoUploadZone.tsx b/src/components/VideoUploadZone.tsx index 024a3b9..8f8eab1 100644 --- a/src/components/VideoUploadZone.tsx +++ b/src/components/VideoUploadZone.tsx @@ -1,33 +1,55 @@ import { type FC } from "react"; import { DocumentUpload, VideoSquare } from "iconsax-react"; +import { clx } from "@/helpers/utils"; type VideoUploadZoneProps = { getRootProps: () => React.HTMLAttributes; getInputProps: () => React.InputHTMLAttributes; + isLoading?: boolean; + loadingLabel?: string; }; -const VideoUploadZone: FC = ({ getRootProps, getInputProps }) => { +const VideoUploadZone: FC = ({ + getRootProps, + getInputProps, + isLoading = false, + loadingLabel = "در حال آپلود...", +}) => { return (
- -
- ویدیو مورد نظر را آپلود کنید -
-
- -
آپلود
-
+ {isLoading ? ( + <> + +
{loadingLabel}
+ + ) : ( + <> + +
+ ویدیو مورد نظر را آپلود کنید +
+
+ +
آپلود
+
+ + )}
); }; diff --git a/src/pages/editor/components/sidebar/instructions/VideoInput.tsx b/src/pages/editor/components/sidebar/instructions/VideoInput.tsx index 0869411..766d932 100644 --- a/src/pages/editor/components/sidebar/instructions/VideoInput.tsx +++ b/src/pages/editor/components/sidebar/instructions/VideoInput.tsx @@ -1,4 +1,4 @@ -import { type FC, useCallback, useMemo } from "react"; +import { type FC, useCallback, useMemo, useState } from "react"; import { useEditorStore, type ToolType } from "@/pages/editor/store/editorStore"; import { useSingleUpload } from "@/pages/uploader/hooks/useUploaderData"; import { CloseCircle } from "iconsax-react"; @@ -9,30 +9,38 @@ const VideoInput: FC = () => { const { objects, addObject, setSelectedObjectId, setTool, deleteObject } = useEditorStore(); const { mutateAsync: uploadFile } = useSingleUpload(); + const [isUploading, setIsUploading] = useState(false); const onDrop = useCallback( async (acceptedFiles: File[]) => { - for (const file of acceptedFiles) { - try { - const result = await uploadFile(file); - const videoUrl = result?.data?.url; - if (!videoUrl) continue; - const videoId = `video-${Date.now()}-${Math.random()}`; - const newVideo = { - id: videoId, - type: "video" as ToolType, - x: 100, - y: 100, - width: 400, - height: 300, - videoUrl, - }; - addObject(newVideo); - setSelectedObjectId(newVideo.id); - setTool("select"); - } catch { - // TODO: show error toast + if (acceptedFiles.length === 0) return; + + setIsUploading(true); + try { + for (const file of acceptedFiles) { + try { + const result = await uploadFile(file); + const videoUrl = result?.data?.url; + if (!videoUrl) continue; + const videoId = `video-${Date.now()}-${Math.random()}`; + const newVideo = { + id: videoId, + type: "video" as ToolType, + x: 100, + y: 100, + width: 400, + height: 300, + videoUrl, + }; + addObject(newVideo); + setSelectedObjectId(newVideo.id); + setTool("select"); + } catch { + // TODO: show error toast + } } + } finally { + setIsUploading(false); } }, [addObject, setSelectedObjectId, setTool, uploadFile] @@ -43,7 +51,8 @@ const VideoInput: FC = () => { accept: { 'video/*': ['.mp4', '.webm', '.ogg', '.mov', '.avi'] }, - multiple: true + multiple: true, + disabled: isUploading, }); const videoObjects = useMemo(() => { @@ -61,6 +70,7 @@ const VideoInput: FC = () => { {videoObjects.length > 0 && (