瀏覽代碼

react: Add dashboard plugin inside component again. add `plugins` option.

Renée Kooi 7 年之前
父節點
當前提交
cfe636d849
共有 3 個文件被更改,包括 50 次插入8 次删除
  1. 5 3
      examples/react-example/App.js
  2. 12 0
      src/plugins/Dashboard/index.js
  3. 33 5
      src/uppy-react/Dashboard.js

+ 5 - 3
examples/react-example/App.js

@@ -23,7 +23,6 @@ module.exports = class App extends React.Component {
   componentWillMount () {
   componentWillMount () {
     this.uppy = new Uppy({ autoProceed: false })
     this.uppy = new Uppy({ autoProceed: false })
       .use(Tus10, { endpoint: 'https://master.tus.io/files' })
       .use(Tus10, { endpoint: 'https://master.tus.io/files' })
-      .use(DashboardPlugin, { inline: true })
       .use(DragDropPlugin, {
       .use(DragDropPlugin, {
         locale: {
         locale: {
           strings: {
           strings: {
@@ -33,7 +32,7 @@ module.exports = class App extends React.Component {
         }
         }
       })
       })
       .use(ProgressBarPlugin)
       .use(ProgressBarPlugin)
-      .use(GoogleDrive, { target: DashboardPlugin, host: 'https://server.uppy.io' })
+      .use(GoogleDrive, { host: 'https://server.uppy.io' })
       .run()
       .run()
 
 
     this.uppy2 = new Uppy({ autoProceed: false })
     this.uppy2 = new Uppy({ autoProceed: false })
@@ -73,7 +72,10 @@ module.exports = class App extends React.Component {
           Show Dashboard
           Show Dashboard
         </label>
         </label>
         {showInlineDashboard && (
         {showInlineDashboard && (
-          <Dashboard uppy={this.uppy} />
+          <Dashboard
+            uppy={this.uppy}
+            plugins={['GoogleDrive']}
+          />
         )}
         )}
 
 
         <h2>Modal Dashboard</h2>
         <h2>Modal Dashboard</h2>

+ 12 - 0
src/plugins/Dashboard/index.js

@@ -424,6 +424,12 @@ module.exports = class DashboardUI extends Plugin {
       this.mount(target, this)
       this.mount(target, this)
     }
     }
 
 
+    const plugins = this.opts.plugins || []
+    plugins.forEach((pluginID) => {
+      const plugin = this.core.getPlugin(pluginID)
+      if (plugin) plugin.mount(this, plugin)
+    })
+
     if (!this.opts.disableStatusBar) {
     if (!this.opts.disableStatusBar) {
       this.core.use(StatusBar, {
       this.core.use(StatusBar, {
         target: this
         target: this
@@ -455,6 +461,12 @@ module.exports = class DashboardUI extends Plugin {
       if (statusBar) this.core.removePlugin(statusBar)
       if (statusBar) this.core.removePlugin(statusBar)
     }
     }
 
 
+    const plugins = this.opts.plugins || []
+    plugins.forEach((pluginID) => {
+      const plugin = this.core.getPlugin(pluginID)
+      if (plugin) plugin.unmount()
+    })
+
     this.unmount()
     this.unmount()
     this.removeActions()
     this.removeActions()
     this.removeEvents()
     this.removeEvents()

+ 33 - 5
src/uppy-react/Dashboard.js

@@ -1,7 +1,7 @@
 const React = require('react')
 const React = require('react')
 const PropTypes = require('prop-types')
 const PropTypes = require('prop-types')
 const UppyCore = require('../core/Core')
 const UppyCore = require('../core/Core')
-const UppyWrapper = require('./Wrapper')
+const DashboardPlugin = require('../plugins/Dashboard')
 
 
 const h = React.createElement
 const h = React.createElement
 
 
@@ -10,14 +10,42 @@ const h = React.createElement
  * renders the Dashboard inline, so you can put it anywhere you want.
  * renders the Dashboard inline, so you can put it anywhere you want.
  */
  */
 
 
-const Dashboard = (props) =>
-  h(UppyWrapper, props)
+class Dashboard extends React.Component {
+  componentDidMount () {
+    const uppy = this.props.uppy
+    const options = Object.assign(
+      {},
+      this.props,
+      { target: this.container }
+    )
+    delete options.uppy
+    uppy.use(DashboardPlugin, options)
+
+    this.plugin = uppy.getPlugin('DashboardUI')
+  }
+
+  componentWillUnmount () {
+    const uppy = this.props.uppy
+
+    uppy.removePlugin(this.plugin)
+  }
+
+  render () {
+    return h('div', {
+      ref: (container) => {
+        this.container = container
+      }
+    })
+  }
+}
 
 
 Dashboard.propTypes = {
 Dashboard.propTypes = {
-  uppy: PropTypes.instanceOf(UppyCore).isRequired
+  uppy: PropTypes.instanceOf(UppyCore).isRequired,
+  inline: PropTypes.bool,
+  plugins: PropTypes.arrayOf(PropTypes.string)
 }
 }
 Dashboard.defaultProps = {
 Dashboard.defaultProps = {
-  plugin: 'DashboardUI'
+  inline: true
 }
 }
 
 
 module.exports = Dashboard
 module.exports = Dashboard