App.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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(DragDropPlugin, {
  23. locale: {
  24. strings: {
  25. chooseFile: 'Boop a file',
  26. orDragDrop: 'or yoink it here'
  27. }
  28. }
  29. })
  30. .use(ProgressBarPlugin)
  31. .use(GoogleDrive, { host: 'https://server.uppy.io' })
  32. .run()
  33. this.uppy2 = new Uppy({ autoProceed: false })
  34. .use(Tus10, { endpoint: 'https://master.tus.io/files' })
  35. .use(DashboardPlugin)
  36. .run()
  37. }
  38. componentWillUnmount () {
  39. this.uppy.close()
  40. this.uppy2.close()
  41. }
  42. handleModalClick () {
  43. this.setState({
  44. open: !this.state.open
  45. })
  46. }
  47. render () {
  48. const { showInlineDashboard } = this.state
  49. return (
  50. <div>
  51. <h1>React Examples</h1>
  52. <h2>Inline Dashboard</h2>
  53. <label>
  54. <input
  55. type="checkbox"
  56. checked={showInlineDashboard}
  57. onChange={(event) => {
  58. this.setState({
  59. showInlineDashboard: event.target.checked
  60. })
  61. }}
  62. />
  63. Show Dashboard
  64. </label>
  65. {showInlineDashboard && (
  66. <Dashboard
  67. uppy={this.uppy}
  68. plugins={['GoogleDrive']}
  69. />
  70. )}
  71. <h2>Modal Dashboard</h2>
  72. <div>
  73. <button onClick={this.handleModalClick}>
  74. {this.state.open ? 'Close dashboard' : 'Open dashboard'}
  75. </button>
  76. <DashboardModal
  77. uppy={this.uppy2}
  78. open={this.state.open}
  79. onRequestClose={() => this.setState({ open: false })}
  80. />
  81. </div>
  82. <h2>Drag Drop Area</h2>
  83. <DragDrop uppy={this.uppy} />
  84. <h2>Progress Bar</h2>
  85. <ProgressBar uppy={this.uppy} />
  86. </div>
  87. )
  88. }
  89. }