Skip to content

Commit

Permalink
Adopted changes in v0.3.0 to basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
lionng429 committed Jun 10, 2016
1 parent 4379caf commit 8da8046
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
78 changes: 48 additions & 30 deletions examples/basic/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var React = require('react');
var ReactDOM = require('react-dom');
var FileUploader = require('../../lib');
var _ = require('lodash');

var MyComponent = React.createClass({
getInitialState: function() {
Expand Down Expand Up @@ -30,7 +31,7 @@ var MyComponent = React.createClass({
//}
},

onFileDrop: function(target, files) {
onFileDrop: function({ target }, files) {
let node = ReactDOM.findDOMNode(this.refs.uploadPanel);
if (target != node) {
return false;
Expand All @@ -51,6 +52,20 @@ var MyComponent = React.createClass({
this.closePanel();
},

onFileProgress: function(file) {
var files = this.state.files;

files.map(function(_file) {
if (_file.id === file.id) {
_file = file;
}
});

this.setState({
files: files
});
},

onFileUpdate: function(file) {
var files = this.state.files;

Expand Down Expand Up @@ -106,36 +121,39 @@ var MyComponent = React.createClass({
}
</p>
</FileUploader.Receiver>
<FileUploader.UploadManager
customClass="upload-list"
files={this.state.files}
uploadUrl="/upload"
onUploadStart={this.onFileUpdate}
onUploadProgress={this.onFileUpdate}
onUploadEnd={this.onFileUpdate} >
<div>
<p>Upload List</p>
{
this.state.files.map(function(file, index) {
return (
<FileUploader.UploadHandler key={index} file={file} autoStart={true}>
<dl>
<dh>{ file.name }</dh>
<dd>
<span className="file__id">{ file.id } </span>
<span className="file__type">{ file.type } </span>
<span className="file__size">{ file.size / 1000 / 1000 } MB</span>
<span className="file__progress">{ file.progress }%</span>
<span className="file__status">
{_this._getStatusString(file.status)}
</span>
<span className="file__error">{ file.error }</span>
</dd>
</dl>
</FileUploader.UploadHandler>
)
})
}
</FileUploader.UploadManager>
<FileUploader.UploadManager
customClass="upload-list"
files={this.state.files}
uploadUrl="/upload"
onUploadStart={this.onFileUpdate}
onUploadProgress={_.debounce(this.onFileProgress, 150)}
onUploadEnd={this.onFileUpdate}
>
{
this.state.files.map(function(file, index) {
return (
<FileUploader.UploadHandler key={index} file={file} autoStart={true}>
<dl>
<dh>{ file.name }</dh>
<dd>
<span className="file__id">{ file.id } </span>
<span className="file__type">{ file.type } </span>
<span className="file__size">{ file.size / 1000 / 1000 } MB</span>
<span className="file__progress">{ file.progress }%</span>
<span className="file__status">
{_this._getStatusString(file.status)}
</span>
<span className="file__error">{ file.error }</span>
</dd>
</dl>
</FileUploader.UploadHandler>
)
})
}
</FileUploader.UploadManager>
</div>
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"connect-multiparty": "^2.0.0",
"express": "^4.13.3",
"forever": "^0.15.1",
"lodash": "^4.13.1",
"react": "^0.14.3",
"react-dom": "^0.14.3"
},
Expand Down

0 comments on commit 8da8046

Please sign in to comment.