Merge pull request #99 from lbryio/master

Release to Master
This commit is contained in:
Job Evers‐Meltzer 2016-12-02 21:15:34 -06:00 committed by GitHub
commit c0e53b45eb
2 changed files with 31 additions and 17 deletions

View file

@ -103,32 +103,35 @@ var DownloadLink = React.createClass({
}) })
}, },
handleClick: function() { handleClick: function() {
this.setState({
downloading: true
});
lbry.getCostEstimate(this.props.streamName, (amount) => { lbry.getCostEstimate(this.props.streamName, (amount) => {
lbry.getBalance((balance) => { lbry.getBalance((balance) => {
if (amount > balance) { if (amount > balance) {
this.setState({ this.setState({
modal: 'notEnoughCredits', modal: 'notEnoughCredits',
downloading: false
}); });
} else { } else {
this.startDownload(); lbry.getStream(this.props.streamName, (streamInfo) => {
if (typeof streamInfo !== 'object') {
this.setState({
modal: 'timedOut',
downloading: false,
});
} else {
this.setState({
modal: 'downloadStarted',
filePath: streamInfo.path,
});
}
});
} }
}); });
}); });
}, },
startDownload: function() {
if (!this.state.downloading) { //@TODO: Continually update this.state.downloading based on actual status of file
this.setState({
downloading: true
});
lbry.getStream(this.props.streamName, (streamInfo) => {
this.setState({
modal: 'downloadStarted',
filePath: streamInfo.path,
});
});
}
},
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);
return ( return (
@ -141,6 +144,9 @@ var DownloadLink = React.createClass({
<Modal isOpen={this.state.modal == 'notEnoughCredits'} onConfirmed={this.closeModal}> <Modal isOpen={this.state.modal == 'notEnoughCredits'} onConfirmed={this.closeModal}>
You don't have enough LBRY credits to pay for this stream. You don't have enough LBRY credits to pay for this stream.
</Modal> </Modal>
<Modal isOpen={this.state.modal == 'timedOut'} onConfirmed={this.closeModal}>
LBRY was unable to download the stream <strong>lbry://{this.props.streamName}</strong>.
</Modal>
</span> </span>
); );
} }
@ -156,11 +162,15 @@ var WatchLink = React.createClass({
hidden: React.PropTypes.bool, hidden: React.PropTypes.bool,
}, },
handleClick: function() { handleClick: function() {
this.setState({
loading: true,
})
lbry.getCostEstimate(this.props.streamName, (amount) => { lbry.getCostEstimate(this.props.streamName, (amount) => {
lbry.getBalance((balance) => { lbry.getBalance((balance) => {
if (amount > balance) { if (amount > balance) {
this.setState({ this.setState({
modal: 'notEnoughCredits', modal: 'notEnoughCredits',
loading: false,
}); });
} else { } else {
window.location = '?watch=' + this.props.streamName; window.location = '?watch=' + this.props.streamName;
@ -171,6 +181,7 @@ var WatchLink = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
modal: null, modal: null,
loading: false,
}; };
}, },
closeModal: function() { closeModal: function() {
@ -188,7 +199,8 @@ var WatchLink = React.createClass({
return ( return (
<span className="button-container"> <span className="button-container">
<Link button={this.props.button} hidden={this.props.hidden} style={this.props.style} <Link button={this.props.button} hidden={this.props.hidden} style={this.props.style}
label={this.props.label} icon={this.props.icon} onClick={this.handleClick} /> disabled={this.state.loading} label={this.props.label} icon={this.props.icon}
onClick={this.handleClick} />
<Modal isOpen={this.state.modal == 'notEnoughCredits'} onConfirmed={this.closeModal}> <Modal isOpen={this.state.modal == 'notEnoughCredits'} onConfirmed={this.closeModal}>
You don't have enough LBRY credits to pay for this stream. You don't have enough LBRY credits to pay for this stream.
</Modal> </Modal>

View file

@ -49,7 +49,9 @@ var Modal = React.createClass({
return ( return (
<ReactModal {...props}> <ReactModal {...props}>
{this.props.children} <div>
{this.props.children}
</div>
{buttons} {buttons}
</ReactModal> </ReactModal>
); );