Add drag and drop. Add drag class. WIP Styles.
parent
6432d3268a
commit
223cdf2e6b
|
@ -28,9 +28,9 @@ const WriteDataBody = ({
|
||||||
: <div className="write-data-form--file">
|
: <div className="write-data-form--file">
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
onChange={handleFile}
|
onChange={e => handleFile(e, false)}
|
||||||
className="write-data-form--upload"
|
className="write-data-form--upload"
|
||||||
ref={r => inputRef = r}
|
ref={r => (inputRef = r)}
|
||||||
accept="text/*, application/gzip"
|
accept="text/*, application/gzip"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React, {Component, PropTypes} from 'react'
|
import React, {Component, PropTypes} from 'react'
|
||||||
|
import classnames from 'classnames'
|
||||||
|
|
||||||
import OnClickOutside from 'shared/components/OnClickOutside'
|
import OnClickOutside from 'shared/components/OnClickOutside'
|
||||||
import WriteDataBody from 'src/data_explorer/components/WriteDataBody'
|
import WriteDataBody from 'src/data_explorer/components/WriteDataBody'
|
||||||
|
@ -16,6 +17,7 @@ class WriteDataForm extends Component {
|
||||||
fileName: '',
|
fileName: '',
|
||||||
progress: '',
|
progress: '',
|
||||||
isManual: false,
|
isManual: false,
|
||||||
|
dragClass: 'drag-none',
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleSelectDatabase = ::this.handleSelectDatabase
|
this.handleSelectDatabase = ::this.handleSelectDatabase
|
||||||
|
@ -69,13 +71,21 @@ class WriteDataForm extends Component {
|
||||||
this.setState({inputContent: e.target.value.trim()})
|
this.setState({inputContent: e.target.value.trim()})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFile(e) {
|
handleFile(e, drop) {
|
||||||
// todo: expect this to be a File or Blob
|
// todo: expect this to be a File or Blob
|
||||||
const file = e.target.files[0]
|
let file
|
||||||
const reader = new FileReader()
|
if (drop) {
|
||||||
reader.readAsText(file)
|
file = e.dataTransfer.files[0]
|
||||||
|
} else {
|
||||||
|
file = e.target.files[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
|
||||||
// async function run when loading of file is complete
|
// async function run when loading of file is complete
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.readAsText(file)
|
||||||
reader.onload = loadEvent => {
|
reader.onload = loadEvent => {
|
||||||
this.setState({
|
this.setState({
|
||||||
uploadContent: loadEvent.target.result,
|
uploadContent: loadEvent.target.result,
|
||||||
|
@ -84,10 +94,38 @@ class WriteDataForm extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleDragOver(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDragClass(entering) {
|
||||||
|
return e => {
|
||||||
|
e.preventDefault()
|
||||||
|
if (entering) {
|
||||||
|
this.setState({
|
||||||
|
dragClass: 'drag-over',
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
dragClass: 'drag-none',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {onClose, errorThrown} = this.props
|
const {onClose, errorThrown} = this.props
|
||||||
|
const {dragClass} = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div
|
||||||
|
onDrop={e => this.handleFile(e, true)}
|
||||||
|
onDragOver={this.handleDragOver}
|
||||||
|
onDragEnter={this.handleDragClass(true)}
|
||||||
|
onDragLeave={this.handleDragClass(false)}
|
||||||
|
className={classnames(OVERLAY_TECHNOLOGY, dragClass)}
|
||||||
|
>
|
||||||
<div className="write-data-form">
|
<div className="write-data-form">
|
||||||
<WriteDataHeader
|
<WriteDataHeader
|
||||||
{...this.state}
|
{...this.state}
|
||||||
|
@ -104,6 +142,7 @@ class WriteDataForm extends Component {
|
||||||
handleSubmit={this.handleSubmit}
|
handleSubmit={this.handleSubmit}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue