| 
									
										
										
										
											2017-01-24 10:07:22 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2019-04-10 02:39:42 +08:00
										 |  |  |  * MinIO Cloud Storage (C) 2016, 2018 MinIO, Inc. | 
					
						
							| 
									
										
										
										
											2017-01-24 10:07:22 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-01 04:22:18 +08:00
										 |  |  | import React from "react" | 
					
						
							|  |  |  | import { connect } from "react-redux" | 
					
						
							|  |  |  | import ReactDropzone from "react-dropzone" | 
					
						
							|  |  |  | import * as actions from "./actions" | 
					
						
							| 
									
										
										
										
											2017-01-24 10:07:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Dropzone is a drag-and-drop element for uploading files. It will create a
 | 
					
						
							|  |  |  | // landing zone of sorts that automatically receives the files.
 | 
					
						
							| 
									
										
										
										
											2018-03-01 04:22:18 +08:00
										 |  |  | export class Dropzone extends React.Component { | 
					
						
							| 
									
										
										
										
											2017-01-24 10:07:22 +08:00
										 |  |  |   onDrop(files) { | 
					
						
							| 
									
										
										
										
											2018-03-01 04:22:18 +08:00
										 |  |  |     const { uploadFile } = this.props | 
					
						
							| 
									
										
										
										
											2017-01-24 10:07:22 +08:00
										 |  |  |     // FIXME: Currently you can upload multiple files, but only one abort
 | 
					
						
							|  |  |  |     // modal will be shown, and progress updates will only occur for one
 | 
					
						
							|  |  |  |     // file at a time. See #171.
 | 
					
						
							|  |  |  |     files.forEach(file => { | 
					
						
							| 
									
										
										
										
											2018-03-01 04:22:18 +08:00
										 |  |  |       uploadFile(file) | 
					
						
							| 
									
										
										
										
											2017-01-24 10:07:22 +08:00
										 |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   render() { | 
					
						
							| 
									
										
										
										
											2018-03-27 03:49:12 +08:00
										 |  |  |     // Overwrite the default styling from react-dropzone; otherwise it
 | 
					
						
							|  |  |  |     // won't handle child elements correctly.
 | 
					
						
							|  |  |  |     const style = { | 
					
						
							|  |  |  |       height: "100%", | 
					
						
							|  |  |  |       borderWidth: "0", | 
					
						
							|  |  |  |       borderStyle: "dashed", | 
					
						
							|  |  |  |       borderColor: "#fff" | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     const activeStyle = { | 
					
						
							|  |  |  |       borderWidth: "2px", | 
					
						
							|  |  |  |       borderColor: "#777" | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     const rejectStyle = { | 
					
						
							|  |  |  |       backgroundColor: "#ffdddd" | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 10:07:22 +08:00
										 |  |  |     // disableClick means that it won't trigger a file upload box when
 | 
					
						
							|  |  |  |     // the user clicks on a file.
 | 
					
						
							|  |  |  |     return ( | 
					
						
							| 
									
										
										
										
											2018-03-01 04:22:18 +08:00
										 |  |  |       <ReactDropzone | 
					
						
							| 
									
										
										
										
											2018-03-27 03:49:12 +08:00
										 |  |  |         style={style} | 
					
						
							|  |  |  |         activeStyle={activeStyle} | 
					
						
							|  |  |  |         rejectStyle={rejectStyle} | 
					
						
							| 
									
										
										
										
											2018-03-01 04:22:18 +08:00
										 |  |  |         disableClick={true} | 
					
						
							|  |  |  |         onDrop={this.onDrop.bind(this)} | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         {this.props.children} | 
					
						
							| 
									
										
										
										
											2017-01-24 10:07:22 +08:00
										 |  |  |       </ReactDropzone> | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-03-01 04:22:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const mapDispatchToProps = dispatch => { | 
					
						
							|  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2018-03-23 03:25:56 +08:00
										 |  |  |     uploadFile: file => dispatch(actions.uploadFile(file)) | 
					
						
							| 
									
										
										
										
											2018-03-01 04:22:18 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default connect(undefined, mapDispatchToProps)(Dropzone) |