Browse Source

hideModal/showModal --> show/hide, isOpen, DashboardUI --> Dashboard

Artur Paikin 7 years ago
parent
commit
c77c6a103d
3 changed files with 32 additions and 21 deletions
  1. 1 1
      src/plugins/Dashboard/Dashboard.js
  2. 29 18
      src/plugins/Dashboard/index.js
  3. 2 2
      src/plugins/StatusBar/index.js

+ 1 - 1
src/plugins/Dashboard/Dashboard.js

@@ -69,7 +69,7 @@ module.exports = function Dashboard (props) {
               type="button"
               aria-label="${props.i18n('closeModal')}"
               title="${props.i18n('closeModal')}"
-              onclick=${props.hideModal}>${closeIcon()}</button>
+              onclick=${props.hide}>${closeIcon()}</button>
 
       <div class="UppyDashboard-innerWrap">
 

+ 29 - 18
src/plugins/Dashboard/index.js

@@ -14,8 +14,8 @@ const { defaultTabIcon } = require('./icons')
 module.exports = class DashboardUI extends Plugin {
   constructor (core, opts) {
     super(core, opts)
-    this.id = 'DashboardUI'
-    this.title = 'Dashboard UI'
+    this.id = 'Dashboard'
+    this.title = 'Dashboard'
     this.type = 'orchestrator'
 
     const defaultLocale = {
@@ -66,8 +66,8 @@ module.exports = class DashboardUI extends Plugin {
     this.translator = new Translator({locale: this.locale})
     this.containerWidth = this.translator.translate.bind(this.translator)
 
-    this.hideModal = this.hideModal.bind(this)
-    this.showModal = this.showModal.bind(this)
+    this.hide = this.hide.bind(this)
+    this.show = this.show.bind(this)
 
     this.addTarget = this.addTarget.bind(this)
     this.actions = this.actions.bind(this)
@@ -143,7 +143,11 @@ module.exports = class DashboardUI extends Plugin {
     })})
   }
 
-  hideModal () {
+  isOpen () {
+    return !this.core.getState().modal.isHidden || false
+  }
+
+  hide () {
     const modal = this.core.getState().modal
 
     this.core.setState({
@@ -157,7 +161,7 @@ module.exports = class DashboardUI extends Plugin {
     window.scrollTo(0, this.savedDocumentScrollPosition)
   }
 
-  showModal () {
+  show () {
     const modal = this.core.getState().modal
 
     this.core.setState({
@@ -185,19 +189,23 @@ module.exports = class DashboardUI extends Plugin {
   // Close the Modal on esc key press
   handleEscapeKeyPress (event) {
     if (event.keyCode === 27) {
-      this.hideModal()
+      this.hide()
     }
   }
 
   handleClickOutside () {
-    if (this.opts.closeModalOnClickOutside) this.hideModal()
+    if (this.opts.closeModalOnClickOutside) this.hide()
   }
 
   initEvents () {
     // Modal open button
     const showModalTrigger = findDOMElement(this.opts.trigger)
     if (!this.opts.inline && showModalTrigger) {
-      showModalTrigger.addEventListener('click', this.showModal)
+      if (Array.isArray(showModalTrigger)) {
+        showModalTrigger.forEach(trigger => trigger.addEventListener('click', this.show))
+      } else {
+        showModalTrigger.addEventListener('click', this.show)
+      }
     }
 
     if (!this.opts.inline && !showModalTrigger) {
@@ -215,7 +223,11 @@ module.exports = class DashboardUI extends Plugin {
   removeEvents () {
     const showModalTrigger = findDOMElement(this.opts.trigger)
     if (!this.opts.inline && showModalTrigger) {
-      showModalTrigger.removeEventListener('click', this.showModal)
+      if (Array.isArray(showModalTrigger)) {
+        showModalTrigger.forEach(trigger => trigger.removeEventListener('click', this.show))
+      } else {
+        showModalTrigger.removeEventListener('click', this.show)
+      }
     }
 
     this.removeDragDropListener()
@@ -259,7 +271,7 @@ module.exports = class DashboardUI extends Plugin {
   }
 
   handleDrop (files) {
-    this.core.log('All right, someone dropped something...')
+    this.core.log('[Dashboard] Files were droppeded')
 
     files.forEach((file) => {
       this.core.addFile({
@@ -300,7 +312,6 @@ module.exports = class DashboardUI extends Plugin {
       inProgressFilesArray.push(files[file])
     })
 
-    // total size and uploaded size
     let totalSize = 0
     let totalUploadedSize = 0
     inProgressFilesArray.forEach((file) => {
@@ -326,7 +337,7 @@ module.exports = class DashboardUI extends Plugin {
     }
 
     const pauseUpload = (fileID) => {
-      this.core.emit.emit('core:upload-pause', fileID)
+      this.core.emit('core:upload-pause', fileID)
     }
 
     const cancelUpload = (fileID) => {
@@ -343,9 +354,9 @@ module.exports = class DashboardUI extends Plugin {
       this.core.emit('dashboard:file-card')
     }
 
-    const info = (text, type, duration) => {
-      this.core.info(text, type, duration)
-    }
+    // const info = (text, type, duration) => {
+    //   this.core.info(text, type, duration)
+    // }
 
     const resumableUploads = this.core.state.capabilities.resumableUploads || false
 
@@ -362,7 +373,7 @@ module.exports = class DashboardUI extends Plugin {
       autoProceed: this.core.opts.autoProceed,
       hideUploadButton: this.opts.hideUploadButton,
       id: this.id,
-      hideModal: this.hideModal,
+      hide: this.hide,
       handleClickOutside: this.handleClickOutside,
       showProgressDetails: this.opts.showProgressDetails,
       inline: this.opts.inline,
@@ -375,7 +386,7 @@ module.exports = class DashboardUI extends Plugin {
       resumeAll: this.resumeAll,
       addFile: this.core.addFile,
       removeFile: this.core.removeFile,
-      info: info,
+      info: this.core.info,
       note: this.opts.note,
       metaFields: state.metaFields,
       resumableUploads: resumableUploads,

+ 2 - 2
src/plugins/StatusBar/index.js

@@ -11,8 +11,8 @@ const prettyBytes = require('prettier-bytes')
 module.exports = class StatusBarUI extends Plugin {
   constructor (core, opts) {
     super(core, opts)
-    this.id = 'StatusBarUI'
-    this.title = 'StatusBar UI'
+    this.id = 'StatusBar'
+    this.title = 'StatusBar'
     this.type = 'progressindicator'
 
     // set default options