瀏覽代碼

Dashboard: Auto close after finish using `closeAfterFinish: true`

Renée Kooi 6 年之前
父節點
當前提交
4b48aac78f
共有 2 個文件被更改,包括 16 次插入1 次删除
  1. 11 1
      packages/@uppy/dashboard/src/index.js
  2. 5 0
      website/src/docs/dashboard.md

+ 11 - 1
packages/@uppy/dashboard/src/index.js

@@ -117,6 +117,7 @@ module.exports = class Dashboard extends Plugin {
       hideProgressAfterFinish: false,
       hideProgressAfterFinish: false,
       note: null,
       note: null,
       closeModalOnClickOutside: false,
       closeModalOnClickOutside: false,
+      closeAfterFinish: false,
       disableStatusBar: false,
       disableStatusBar: false,
       disableInformer: false,
       disableInformer: false,
       disableThumbnailGenerator: false,
       disableThumbnailGenerator: false,
@@ -458,7 +459,16 @@ module.exports = class Dashboard extends Plugin {
     this.uppy.on('plugin-remove', this.removeTarget)
     this.uppy.on('plugin-remove', this.removeTarget)
     this.uppy.on('file-added', (ev) => {
     this.uppy.on('file-added', (ev) => {
       this.toggleAddFilesPanel(false)
       this.toggleAddFilesPanel(false)
-      this.hideAllPanels()
+    })
+    this.uppy.on('complete', ({ uploadID }) => {
+      const { currentUploads } = this.uppy.getState()
+      if (this.opts.closeAfterFinish &&
+          // This is the very last upload still in state
+          // (and will be removed by core after this handler is complete)
+          Object.keys(currentUploads).length === 1 && currentUploads[uploadID]) {
+        // All uploads are done
+        this.requestCloseModal()
+      }
     })
     })
   }
   }
 
 

+ 5 - 0
website/src/docs/dashboard.md

@@ -71,6 +71,7 @@ uppy.use(Dashboard, {
   hideProgressAfterFinish: false,
   hideProgressAfterFinish: false,
   note: null,
   note: null,
   closeModalOnClickOutside: false,
   closeModalOnClickOutside: false,
+  closeAfterFinish: false,
   disableStatusBar: false,
   disableStatusBar: false,
   disableInformer: false,
   disableInformer: false,
   disableThumbnailGenerator: false,
   disableThumbnailGenerator: false,
@@ -184,6 +185,10 @@ Note that this metadata will only be set on a file object if it is entered by th
 
 
 Set to true to automatically close the modal when the user clicks outside of it.
 Set to true to automatically close the modal when the user clicks outside of it.
 
 
+### `closeAfterFinish: false`
+
+Set to true to automatically close the modal when all current uploads are complete. You can use this together with the [`allowMultipleUploads: false`](/docs/uppy#allowMultipleUploads-true) option in Uppy Core to create a smooth experience when uploading a single (batch of) file(s).
+
 ### `disablePageScrollWhenModalOpen: true`
 ### `disablePageScrollWhenModalOpen: true`
 
 
 Page scrolling is disabled by default when the Dashboard modal is open, so when you scroll a list of files in Uppy, the website in the background stays still. Set to false to override this behaviour and leave page scrolling intact.
 Page scrolling is disabled by default when the Dashboard modal is open, so when you scroll a list of files in Uppy, the website in the background stays still. Set to false to override this behaviour and leave page scrolling intact.