Przeglądaj źródła

add isUploading val

reiji-h 2 lat temu
rodzic
commit
c93052d1e6

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