Selaa lähdekoodia

@uppy/core: bring back resetProgress (#5320)

Merlijn Vos 9 kuukautta sitten
vanhempi
commit
810922b309
1 muutettua tiedostoa jossa 27 lisäystä ja 1 poistoa
  1. 27 1
      packages/@uppy/core/src/Uppy.ts

+ 27 - 1
packages/@uppy/core/src/Uppy.ts

@@ -23,7 +23,10 @@ import type {
   CompanionClientProvider,
   CompanionClientSearchProvider,
 } from '@uppy/utils/lib/CompanionClientProvider'
-import type { FileProgressStarted } from '@uppy/utils/lib/FileProgress'
+import type {
+  FileProgressNotStarted,
+  FileProgressStarted,
+} from '@uppy/utils/lib/FileProgress'
 import type {
   Locale,
   I18n,
@@ -616,6 +619,29 @@ export class Uppy<M extends Meta, B extends Body = Record<string, never>> {
     this.setState(undefined) // so that UI re-renders with new options
   }
 
+  resetProgress(): void {
+    const defaultProgress: Omit<FileProgressNotStarted, 'bytesTotal'> = {
+      percentage: 0,
+      bytesUploaded: false,
+      uploadComplete: false,
+      uploadStarted: null,
+    }
+    const files = { ...this.getState().files }
+    const updatedFiles: State<M, B>['files'] = Object.create(null)
+
+    Object.keys(files).forEach((fileID) => {
+      updatedFiles[fileID] = {
+        ...files[fileID],
+        progress: {
+          ...files[fileID].progress,
+          ...defaultProgress,
+        },
+      }
+    })
+
+    this.setState({ files: updatedFiles, ...defaultUploadState })
+  }
+
   clear(): void {
     const { capabilities, currentUploads } = this.getState()
     if (