-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add progress bar for upload + cancel
- Loading branch information
Showing
4 changed files
with
190 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, { Component } from 'react'; | ||
|
||
export default class ProgressBarMenuButton extends Component { | ||
propTypes: { | ||
progress : React.PropTypes.number.isRequired, | ||
click : React.PropTypes.func.isRequired | ||
} | ||
|
||
constructor(){ | ||
super() | ||
|
||
this.state = { | ||
expanded: false | ||
} | ||
} | ||
|
||
_leave(e){ | ||
this.setState({expanded: false}) | ||
var target = $(e.target) | ||
var oldWidth = target.width() | ||
target.html('{}%'.format(this.props.progress)) | ||
target.animate({ | ||
width: '41px' | ||
}, 100) | ||
} | ||
|
||
_enter(e){ | ||
this.setState({expanded: true}) | ||
var target = $(e.target) | ||
var oldWidth = target.width() | ||
var template = `<div class="progress" style="margin-bottom:0px"> | ||
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-value-now={} aria-value-max="100" style="width:{}%"> | ||
{}% | ||
</div></div>`.formatAll(this.props.progress) | ||
target.html(template) | ||
target.animate({ | ||
width: '150px' | ||
}, 100) | ||
} | ||
|
||
componentWillReceiveProps(nextProps){ | ||
if (this.state.expanded){ | ||
var template = `<div class="progress" style="margin-bottom:0px"> | ||
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-value-now={} aria-value-max="100" style="width:{}%"> | ||
{}% | ||
</div></div>`.formatAll(nextProps.progress) | ||
$(this.refs.btn).html(template) | ||
}else{ | ||
$(this.refs.btn).html('{}%'.format(nextProps.progress)) | ||
} | ||
|
||
this.forceUpdate() | ||
} | ||
|
||
shouldComponentUpdate(nextProps, nextState){ | ||
return true | ||
} | ||
|
||
componentDidMount(){ | ||
$(this.refs.btn).html('{}%'.format(this.props.progress)) | ||
$(this.refs.btn).css('padding','6px 0px 6px 0px') | ||
$(this.refs.btn).css('width','41px') | ||
} | ||
|
||
render() { | ||
return ( | ||
<button ref="btn" onClick={this.props.click} onMouseLeave={this._leave.bind(this)} onMouseEnter={this._enter.bind(this)} className="btn" /> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { Component } from 'react'; | ||
|
||
var Modal = require('react-bootstrap').Modal; | ||
|
||
export default class CancelUploadModal extends Component { | ||
|
||
constructor(){ | ||
super(); | ||
this.state = { | ||
open: false | ||
} | ||
} | ||
|
||
closeModal(){ | ||
this.setState({ open: false }) | ||
} | ||
|
||
closeAndCancel(){ | ||
this.setState({ open: false }) | ||
emitter.emit('cancelUpload'); | ||
} | ||
|
||
openModal(){ | ||
this.setState({open: true}) | ||
} | ||
|
||
componentDidMount() { | ||
emitter.on('showCancelUpload', this.openModal.bind(this)) | ||
} | ||
|
||
render() { | ||
return ( | ||
<Modal | ||
show={this.state.open} | ||
onHide={this.closeModal} | ||
aria-labelledby="CanceulUploadHeader"> | ||
|
||
<Modal.Header closeButton={true}> | ||
<Modal.Title id="CancelUploadHeader">Cancel Upload</Modal.Title> | ||
</Modal.Header> | ||
|
||
<Modal.Body> | ||
<p>Are you sure you want to cancel the upload?</p> | ||
</Modal.Body> | ||
|
||
<Modal.Footer> | ||
<button type="button" className="btn btn-danger" onClick={this.closeAndCancel.bind(this)}> | ||
Stop Upload | ||
</button> | ||
<button type="button" className="btn btn-primary" onClick={this.closeModal.bind(this)}> | ||
Cancel | ||
</button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
} | ||
} |