| 147 | } |
| 148 | |
| 149 | onDrop(files) { |
| 150 | const {multiple, setProps} = this.props; |
| 151 | const newProps = { |
| 152 | contents: [], |
| 153 | filename: [], |
| 154 | last_modified: [], |
| 155 | }; |
| 156 | files.forEach(file => { |
| 157 | const reader = new FileReader(); |
| 158 | reader.onload = () => { |
| 159 | /* |
| 160 | * I'm not sure if reader.onload will be executed in order. |
| 161 | * For example, if the 1st file is larger than the 2nd one, |
| 162 | * the 2nd file might load first. |
| 163 | */ |
| 164 | newProps.contents.push(reader.result); |
| 165 | newProps.filename.push(file.name); |
| 166 | // eslint-disable-next-line no-magic-numbers |
| 167 | newProps.last_modified.push(file.lastModified / 1000); |
| 168 | if (newProps.contents.length === files.length) { |
| 169 | if (multiple) { |
| 170 | setProps(newProps); |
| 171 | } else { |
| 172 | setProps({ |
| 173 | contents: newProps.contents[0], |
| 174 | filename: newProps.filename[0], |
| 175 | last_modified: newProps.last_modified[0], |
| 176 | }); |
| 177 | } |
| 178 | } |
| 179 | }; |
| 180 | reader.readAsDataURL(file); |
| 181 | }); |
| 182 | } |
| 183 | |
| 184 | render() { |
| 185 | const { |