Kaynağa Gözat

Clear uploads on `cancelAll`, fixes #660

Renée Kooi 7 yıl önce
ebeveyn
işleme
324883d979
2 değiştirilmiş dosya ile 24 ekleme ve 1 silme
  1. 13 1
      src/core/Core.js
  2. 11 0
      src/core/Core.test.js

+ 13 - 1
src/core/Core.js

@@ -530,7 +530,19 @@ class Uppy {
 
 
   cancelAll () {
   cancelAll () {
     this.emit('cancel-all')
     this.emit('cancel-all')
-    this.setState({ files: {}, totalProgress: 0 })
+
+    // TODO Or should we just call removeFile on all files?
+    const { currentUploads } = this.getState()
+    const uploadIDs = Object.keys(currentUploads)
+
+    uploadIDs.forEach((id) => {
+      this._removeUpload(id)
+    })
+
+    this.setState({
+      files: {},
+      totalProgress: 0
+    })
   }
   }
 
 
   retryUpload (fileID) {
   retryUpload (fileID) {

+ 11 - 0
src/core/Core.test.js

@@ -244,6 +244,17 @@ describe('src/Core', () => {
     })
     })
   })
   })
 
 
+  it('should clear all uploads on cancelAll()', () => {
+    const core = new Core()
+    const id = core._createUpload([ 'a', 'b' ])
+
+    expect(core.state.currentUploads[id]).toBeDefined()
+
+    core.cancelAll()
+
+    expect(core.state.currentUploads[id]).toBeUndefined()
+  })
+
   it('should close, reset and uninstall when the close method is called', () => {
   it('should close, reset and uninstall when the close method is called', () => {
     const core = new Core()
     const core = new Core()
     core.use(AcquirerPlugin1)
     core.use(AcquirerPlugin1)