Browse Source

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

Renée Kooi 6 years ago
parent
commit
4b48aac78f
2 changed files with 16 additions and 1 deletions
  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,
       note: null,
       closeModalOnClickOutside: false,
+      closeAfterFinish: false,
       disableStatusBar: false,
       disableInformer: false,
       disableThumbnailGenerator: false,
@@ -458,7 +459,16 @@ module.exports = class Dashboard extends Plugin {
     this.uppy.on('plugin-remove', this.removeTarget)
     this.uppy.on('file-added', (ev) => {
       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,
   note: null,
   closeModalOnClickOutside: false,
+  closeAfterFinish: false,
   disableStatusBar: false,
   disableInformer: 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.
 
+### `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`
 
 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.