fortana-co / react-dropzone-uploader

React file dropzone and uploader
https://react-dropzone-uploader.js.org/
MIT License
447 stars 184 forks source link

issue with initial files #217

Open mortezakarimi opened 4 months ago

mortezakarimi commented 4 months ago

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch react-dropzone-uploader@2.11.0 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-dropzone-uploader/dist/Dropzone.tsx b/node_modules/react-dropzone-uploader/dist/Dropzone.tsx
index da29a80..d9cc8b8 100644
--- a/node_modules/react-dropzone-uploader/dist/Dropzone.tsx
+++ b/node_modules/react-dropzone-uploader/dist/Dropzone.tsx
@@ -210,7 +210,7 @@ export interface IDropzoneProps {
   autoUpload: boolean
   timeout?: number

-  initialFiles?: File[]
+  initialFiles?: IFileWithMeta[]

   /* component customization */
   disabled: boolean | CustomizationFunction<boolean>
@@ -255,12 +255,12 @@ class Dropzone extends React.Component<IDropzoneProps, { active: boolean; dragge
   }

   componentDidMount() {
-    if (this.props.initialFiles) this.handleFiles(this.props.initialFiles)
+    if (this.props.initialFiles) this.files = this.props.initialFiles
   }

   componentDidUpdate(prevProps: IDropzoneProps) {
     const { initialFiles } = this.props
-    if (prevProps.initialFiles !== initialFiles && initialFiles) this.handleFiles(initialFiles)
+    if (prevProps.initialFiles !== initialFiles && initialFiles) this.files = initialFiles
   }

   componentWillUnmount() {
@@ -488,7 +488,7 @@ class Dropzone extends React.Component<IDropzoneProps, { active: boolean; dragge
         fileWithMeta.meta.videoHeight = video.videoHeight
       }
       if (!isImage) URL.revokeObjectURL(objectUrl)
-    } catch (e) {
+    } catch (e:any) {
       URL.revokeObjectURL(objectUrl)
     }
     this.forceUpdate()
@@ -500,7 +500,7 @@ class Dropzone extends React.Component<IDropzoneProps, { active: boolean; dragge
     let params: IUploadParams | null = null
     try {
       params = await getUploadParams(fileWithMeta)
-    } catch (e) {
+    } catch (e:any) {
       console.error('Error Upload Params', e.stack)
     }
     if (params === null) return
@@ -630,7 +630,7 @@ class Dropzone extends React.Component<IDropzoneProps, { active: boolean; dragge
     const SubmitButton = SubmitButtonComponent || SubmitButtonDefault
     const Layout = LayoutComponent || LayoutDefault

-    let previews = null
+    let previews:any = null
     if (PreviewComponent !== null) {
       previews = files.map(f => {
         return (
diff --git a/node_modules/react-dropzone-uploader/dist/utils.ts b/node_modules/react-dropzone-uploader/dist/utils.ts
index 707918d..dcb10b9 100644
--- a/node_modules/react-dropzone-uploader/dist/utils.ts
+++ b/node_modules/react-dropzone-uploader/dist/utils.ts
@@ -94,7 +94,7 @@ export const mergeStyles = (
 export const getFilesFromEvent = (
   event: React.DragEvent<HTMLElement> | React.ChangeEvent<HTMLInputElement>,
 ): Array<File | DataTransferItem> => {
-  let items = null
+  let items:any = null

   if ('dataTransfer' in event) {
     const dt = event.dataTransfer

This issue body was partially generated by patch-package.