App.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* eslint-disable */
  2. const React = require('react')
  3. const Uppy = require('uppy/lib/core')
  4. const Tus10 = require('uppy/lib/plugins/Tus10')
  5. const GoogleDrive = require('uppy/lib/plugins/GoogleDrive')
  6. const DashboardPlugin = require('uppy/lib/plugins/Dashboard')
  7. const DragDropPlugin = require('uppy/lib/plugins/DragDrop')
  8. const ProgressBarPlugin = require('uppy/lib/plugins/ProgressBar')
  9. const { Dashboard, DashboardModal, DragDrop, ProgressBar } = require('uppy/lib/uppy-react')
  10. module.exports = class App extends React.Component {
  11. constructor (props) {
  12. super(props)
  13. this.state = {
  14. showInlineDashboard: false,
  15. open: false
  16. }
  17. this.handleModalClick = this.handleModalClick.bind(this)
  18. }
  19. componentWillMount () {
  20. this.uppy = new Uppy({ autoProceed: false })
  21. .use(Tus10, { endpoint: 'https://master.tus.io/files' })
  22. .use(DashboardPlugin, { inline: true })
  23. .use(DragDropPlugin, {
  24. locale: {
  25. strings: {
  26. chooseFile: 'Boop a file',
  27. orDragDrop: 'or yoink it here'
  28. }
  29. }
  30. })
  31. .use(ProgressBarPlugin)
  32. .use(GoogleDrive, { target: DashboardPlugin, host: 'https://server.uppy.io' })
  33. .run()
  34. this.uppy2 = new Uppy({ autoProceed: false })
  35. .use(Tus10, { endpoint: 'https://master.tus.io/files' })
  36. .use(DashboardPlugin)
  37. .run()
  38. }
  39. componentWillUnmount () {
  40. this.uppy.close()
  41. this.uppy2.close()
  42. }
  43. handleModalClick () {
  44. this.setState({
  45. open: !this.state.open
  46. })
  47. }
  48. render () {
  49. const { showInlineDashboard } = this.state
  50. return (
  51. <div>
  52. <h1>React Examples</h1>
  53. <h2>Inline Dashboard</h2>
  54. <label>
  55. <input
  56. type="checkbox"
  57. checked={showInlineDashboard}
  58. onChange={(event) => {
  59. this.setState({
  60. showInlineDashboard: event.target.checked
  61. })
  62. }}
  63. />
  64. Show Dashboard
  65. </label>
  66. {showInlineDashboard && (
  67. <Dashboard uppy={this.uppy} />
  68. )}
  69. <h2>Modal Dashboard</h2>
  70. <div>
  71. <button onClick={this.handleModalClick}>
  72. {this.state.open ? 'Close dashboard' : 'Open dashboard'}
  73. </button>
  74. <DashboardModal
  75. uppy={this.uppy2}
  76. open={this.state.open}
  77. onRequestClose={() => this.setState({ open: false })}
  78. />
  79. </div>
  80. <h2>Drag Drop Area</h2>
  81. <DragDrop uppy={this.uppy} />
  82. <h2>Progress Bar</h2>
  83. <ProgressBar uppy={this.uppy} />
  84. </div>
  85. )
  86. }
  87. }