reiji-h 2 лет назад
Родитель
Сommit
c93052d1e6
1 измененных файлов с 18 добавлено и 4 удалено
  1. 18 4
      packages/editor/src/services/file-dropzone/use-file-dropzone.ts

+ 18 - 4
packages/editor/src/services/file-dropzone/use-file-dropzone.ts

@@ -1,27 +1,41 @@
-import { useCallback } from 'react';
+import { useCallback, useState } from 'react';
 
 import { useDropzone } from 'react-dropzone';
 import type { DropzoneState } from 'react-dropzone';
 
+type FileDropzoneState = DropzoneState & {
+  isUploading: boolean,
+}
+
 type DropzoneEditor = {
   onUpload?: (files: File[]) => void,
 }
 
-export const useFileDropzone = (props: DropzoneEditor): DropzoneState => {
+export const useFileDropzone = (props: DropzoneEditor): FileDropzoneState => {
 
   const { onUpload } = props;
 
+  const [isUploading, setIsUploading] = useState(false);
+
   const dropHandler = useCallback((acceptedFiles: File[]) => {
     if (onUpload == null) {
       return;
     }
+
+    setIsUploading(true);
     onUpload(acceptedFiles);
-  }, [onUpload]);
+    setIsUploading(false);
+
+  }, [onUpload, setIsUploading]);
 
-  return useDropzone({
+  const dropzoneState = useDropzone({
     noKeyboard: true,
     noClick: true,
     onDrop: dropHandler,
   });
 
+  return {
+    ...dropzoneState,
+    isUploading,
+  };
 };