Make Download link switch to "Downloading" immediately on click

This commit is contained in:
Alex Liebowitz 2016-11-23 23:16:02 -05:00
parent 68b377e7a6
commit 468692b480

View file

@ -103,24 +103,19 @@ var DownloadLink = React.createClass({
}) })
}, },
handleClick: function() { handleClick: function() {
lbry.getCostEstimate(this.props.streamName, (amount) => {
lbry.getBalance((balance) => {
if (amount > balance) {
this.setState({
modal: 'notEnoughCredits',
});
} else {
this.startDownload();
}
});
});
},
startDownload: function() {
if (!this.state.downloading) { //@TODO: Continually update this.state.downloading based on actual status of file if (!this.state.downloading) { //@TODO: Continually update this.state.downloading based on actual status of file
this.setState({ this.setState({
downloading: true downloading: true
}); });
lbry.getCostEstimate(this.props.streamName, (amount) => {
lbry.getBalance((balance) => {
if (amount > balance) {
this.setState({
modal: 'notEnoughCredits',
downloading: false
});
} else {
lbry.getStream(this.props.streamName, (streamInfo) => { lbry.getStream(this.props.streamName, (streamInfo) => {
this.setState({ this.setState({
modal: 'downloadStarted', modal: 'downloadStarted',
@ -128,6 +123,9 @@ var DownloadLink = React.createClass({
}); });
}); });
} }
});
});
}
}, },
render: function() { render: function() {
var label = (!this.state.downloading ? this.props.label : this.props.downloadingLabel); var label = (!this.state.downloading ? this.props.label : this.props.downloadingLabel);