-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathLogUploader.js
More file actions
42 lines (36 loc) · 987 Bytes
/
LogUploader.js
File metadata and controls
42 lines (36 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {Component} from 'react';
import Dropzone from 'react-dropzone';
import style from './LogUploader.css';
export class LogUploader extends Component {
state = {
message: 'Load log file...'
};
isLog (content) {
return content[0] === '{' && content[content.length - 1] === '}';
}
onDrop = (files) => {
const file = files[0];
const reader = new FileReader();
reader.onload = (e) => {
const content = e.target.result.trim();
if (!this.isLog(content)) {
this.setState({message: 'Invalid log file'});
return;
}
this.props.onCustomLogFile(content);
};
reader.readAsText(file);
};
render () {
const dropStyle = {
display: 'inline-block',
margin: '5px'
};
return (
<Dropzone multiple={false} accept="text/*" className={"button"} style={dropStyle}
onDrop={this.onDrop}>
{({getRootProps, getInputProps}) => <button {...getRootProps()}>{this.state.message}<input {...getInputProps()}/></button>}
</Dropzone>
);
}
}