-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDropzone.js
77 lines (71 loc) · 1.88 KB
/
Dropzone.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, { useEffect, useState } from "react";
import { useDropzone } from "react-dropzone";
import { Typography } from "@material-ui/core";
const thumb = {
textAlign: "center",
boxSizing: "border-box",
};
const thumbInner = {
textAlign: "center",
marginTop: "1em",
};
function Dropzone(props) {
const [files, setFiles] = useState([]);
const { getRootProps, getInputProps } = useDropzone({
accept: "application/pdf",
multiple: false,
noDrag: false,
onDrop: (acceptedFiles) => {
const files = acceptedFiles.map((file) =>
Object.assign(file, {
preview: URL.createObjectURL(file),
})
);
setFiles(files);
if (props.onChange) {
const data = new FormData();
data.append("files", files[0]);
// console.log(files[0]);
props.onChange(data);
}
},
});
// const removeFile = file => () => {
// const newFiles = [...files];
// newFiles.splice(newFiles.indexOf(file), 1);
// setFiles(newFiles);
// };
const thumbs = files.map((file) => (
<div style={thumb} key={file.name}>
<div style={thumbInner}>
<Typography variant="button" display="block">
{file.name}
</Typography>
</div>
</div>
));
useEffect(
() => () => {
// Make sure to revoke the data uris to avoid memory leaks
files.forEach((file) => URL.revokeObjectURL(file.preview));
},
[files]
);
const rootprops = getRootProps({ className: "btn-dropzone" });
return (
<div style={{ padding: 20 }}>
<div {...rootprops}>
<input {...getInputProps()} />
<Typography
variant="button"
display="block"
style={{ textAlign: "center" }}
>
<strong>Click to upload, or drag resume here</strong>
</Typography>
{thumbs}
</div>
</div>
);
}
export default Dropzone;