uppy/examples/react-example/App.js
Mikael Finstad 8ed210545c
proposal: Cancel assemblies optional (#3575)
* change cancel logic

to make canceling assemblies optional
possibly fixes #3547

* add forgotten file

* rewrite to reason='user'

* try to fix crash

* change reason to unmount

* Apply suggestions from code review

* add close+unmount in more code examples

also fix rule of hooks issue

* improve reason docs

* add tests

* add options also to reset

* update doc

* also prevent canceling uploads on unmount

* Update website/src/docs/transloadit.md

Co-authored-by: Merlijn Vos <merlijn@soverin.net>

* remove conflicting file

Co-authored-by: Merlijn Vos <merlijn@soverin.net>
2022-05-06 01:53:46 +07:00

104 lines
2.6 KiB
JavaScript

/* eslint-disable */
const React = require('react')
const Uppy = require('@uppy/core')
const Tus = require('@uppy/tus')
const GoogleDrive = require('@uppy/google-drive')
const { Dashboard, DashboardModal, DragDrop, ProgressBar, FileInput } = require('@uppy/react')
module.exports = class App extends React.Component {
constructor (props) {
super(props)
this.state = {
showInlineDashboard: false,
open: false
}
this.uppy = new Uppy({ id: 'uppy1', autoProceed: true, debug: true })
.use(Tus, { endpoint: 'https://tusd.tusdemo.net/files/' })
.use(GoogleDrive, { companionUrl: 'https://companion.uppy.io' })
this.uppy2 = new Uppy({ id: 'uppy2', autoProceed: false, debug: true })
.use(Tus, { endpoint: 'https://tusd.tusdemo.net/files/' })
this.handleModalClick = this.handleModalClick.bind(this)
}
componentWillUnmount () {
this.uppy.close({ reason: 'unmount' })
this.uppy2.close({ reason: 'unmount' })
}
handleModalClick () {
this.setState({
open: !this.state.open
})
}
render () {
const { showInlineDashboard } = this.state
return (
<div>
<h1>React Examples</h1>
<h2>Inline Dashboard</h2>
<label>
<input
type="checkbox"
checked={showInlineDashboard}
onChange={(event) => {
this.setState({
showInlineDashboard: event.target.checked
})
}}
/>
Show Dashboard
</label>
{showInlineDashboard && (
<Dashboard
uppy={this.uppy}
plugins={['GoogleDrive']}
metaFields={[
{ id: 'name', name: 'Name', placeholder: 'File name' }
]}
/>
)}
<h2>Modal Dashboard</h2>
<div>
<button onClick={this.handleModalClick}>
{this.state.open ? 'Close dashboard' : 'Open dashboard'}
</button>
<DashboardModal
uppy={this.uppy2}
open={this.state.open}
target={document.body}
onRequestClose={() => this.setState({ open: false })}
/>
</div>
<h2>Drag Drop Area</h2>
<DragDrop
uppy={this.uppy}
locale={{
strings: {
chooseFile: 'Boop a file',
orDragDrop: 'or yoink it here'
}
}}
/>
<h2>Progress Bar</h2>
<ProgressBar
uppy={this.uppy}
hideAfterFinish={false}
/>
<h2>File Input</h2>
<FileInput
uppy={this.uppy}
/>
</div>
)
}
}