2016-08-07 22:36:57 +02:00
|
|
|
var Link = React.createClass({
|
|
|
|
handleClick: function() {
|
|
|
|
if (this.props.onClick) {
|
|
|
|
this.props.onClick();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var href = this.props.href ? this.props.href : 'javascript:;',
|
2016-08-07 23:05:04 +02:00
|
|
|
icon = this.props.icon ? <Icon icon={this.props.icon} fixed={true} /> : '',
|
|
|
|
className = (this.props.className ? this.props.className : '') +
|
|
|
|
(this.props.button ? ' button-block button-' + this.props.button : '') +
|
|
|
|
(this.props.hidden ? ' hidden' : '') +
|
|
|
|
(this.props.disabled ? ' disabled' : '');
|
2016-08-07 22:36:57 +02:00
|
|
|
|
|
|
|
return (
|
2016-08-07 23:05:04 +02:00
|
|
|
<a className={className ? className : 'button-text'} href={href} style={this.props.style ? this.props.style : {}}
|
2016-08-07 22:36:57 +02:00
|
|
|
title={this.props.title} onClick={this.handleClick}>
|
|
|
|
{this.props.icon ? icon : '' }
|
2016-08-08 02:20:14 +02:00
|
|
|
<span className="link-label">{this.props.label}</span>
|
|
|
|
{this.props.badge ? <span className="badge">{this.props.badge}</span> : '' }
|
2016-08-07 22:36:57 +02:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-07 22:10:44 +02:00
|
|
|
var linkContainerStyle = {
|
|
|
|
position: 'relative',
|
|
|
|
};
|
|
|
|
|
2016-08-07 22:36:57 +02:00
|
|
|
var ToolTipLink = React.createClass({
|
2016-08-07 22:10:44 +02:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
showTooltip: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
handleClick: function() {
|
|
|
|
if (this.props.tooltip) {
|
|
|
|
this.setState({
|
|
|
|
showTooltip: !this.state.showTooltip,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.props.onClick) {
|
|
|
|
this.props.onClick();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleTooltipMouseOut: function() {
|
|
|
|
this.setState({
|
|
|
|
showTooltip: false,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var href = this.props.href ? this.props.href : 'javascript:;',
|
|
|
|
icon = this.props.icon ? <Icon icon={this.props.icon} /> : '',
|
2016-08-07 23:05:04 +02:00
|
|
|
className = this.props.className +
|
|
|
|
(this.props.button ? ' button-block button-' + this.props.button : '') +
|
|
|
|
(this.props.hidden ? ' hidden' : '') +
|
|
|
|
(this.props.disabled ? ' disabled' : '');
|
2016-08-07 22:10:44 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<span style={linkContainerStyle}>
|
2016-08-07 23:05:04 +02:00
|
|
|
<a className={className ? className : 'button-text'} href={href} style={this.props.style ? this.props.style : {}}
|
2016-08-07 22:10:44 +02:00
|
|
|
title={this.props.title} onClick={this.handleClick}>
|
|
|
|
{this.props.icon ? icon : '' }
|
|
|
|
{this.props.label}
|
|
|
|
</a>
|
|
|
|
{(!this.props.tooltip ? null :
|
|
|
|
<ToolTip open={this.state.showTooltip} onMouseOut={this.handleTooltipMouseOut}>
|
|
|
|
{this.props.tooltip}
|
|
|
|
</ToolTip>
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var DownloadLink = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
type: React.PropTypes.string,
|
|
|
|
streamName: React.PropTypes.string,
|
|
|
|
label: React.PropTypes.string,
|
|
|
|
downloadingLabel: React.PropTypes.string,
|
|
|
|
button: React.PropTypes.string,
|
|
|
|
style: React.PropTypes.object,
|
|
|
|
hidden: React.PropTypes.bool,
|
|
|
|
},
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
icon: 'icon-download',
|
|
|
|
label: 'Download',
|
|
|
|
downloadingLabel: 'Downloading...',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
downloading: false,
|
2016-10-21 09:53:45 +02:00
|
|
|
filePath: null,
|
|
|
|
modal: null,
|
2016-08-07 22:10:44 +02:00
|
|
|
}
|
|
|
|
},
|
2016-10-21 09:53:45 +02:00
|
|
|
closeModal: function() {
|
|
|
|
this.setState({
|
|
|
|
modal: null,
|
|
|
|
})
|
|
|
|
},
|
2016-08-07 22:10:44 +02:00
|
|
|
handleClick: function() {
|
|
|
|
lbry.getCostEstimate(this.props.streamName, (amount) => {
|
|
|
|
lbry.getBalance((balance) => {
|
|
|
|
if (amount > balance) {
|
2016-10-21 09:53:45 +02:00
|
|
|
this.setState({
|
|
|
|
modal: 'notEnoughCredits',
|
|
|
|
});
|
2016-08-07 22:10:44 +02:00
|
|
|
} else {
|
|
|
|
this.startDownload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
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) => {
|
2016-10-21 09:53:45 +02:00
|
|
|
this.setState({
|
|
|
|
modal: 'downloadStarted',
|
|
|
|
filePath: streamInfo.path,
|
|
|
|
});
|
2016-08-07 22:10:44 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var label = (!this.state.downloading ? this.props.label : this.props.downloadingLabel);
|
2016-10-21 09:53:45 +02:00
|
|
|
return (
|
2016-10-28 14:51:15 +02:00
|
|
|
<span className="button-container">
|
2016-10-21 09:53:45 +02:00
|
|
|
<Link button={this.props.button} hidden={this.props.hidden} style={this.props.style}
|
|
|
|
disabled={this.state.downloading} label={label} icon={this.props.icon} onClick={this.handleClick} />
|
|
|
|
<Modal isOpen={this.state.modal == 'downloadStarted'} onConfirmed={this.closeModal}>
|
|
|
|
Downloading to {this.state.filePath}
|
|
|
|
</Modal>
|
|
|
|
<Modal isOpen={this.state.modal == 'notEnoughCredits'} onConfirmed={this.closeModal}>
|
|
|
|
You don't have enough LBRY credits to pay for this stream.
|
|
|
|
</Modal>
|
2016-10-22 09:38:39 +02:00
|
|
|
</span>
|
2016-10-21 09:53:45 +02:00
|
|
|
);
|
2016-08-07 22:10:44 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var WatchLink = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
type: React.PropTypes.string,
|
|
|
|
streamName: React.PropTypes.string,
|
|
|
|
label: React.PropTypes.string,
|
|
|
|
button: React.PropTypes.string,
|
|
|
|
style: React.PropTypes.object,
|
|
|
|
hidden: React.PropTypes.bool,
|
|
|
|
},
|
|
|
|
handleClick: function() {
|
|
|
|
lbry.getCostEstimate(this.props.streamName, (amount) => {
|
|
|
|
lbry.getBalance((balance) => {
|
|
|
|
if (amount > balance) {
|
2016-10-21 09:53:45 +02:00
|
|
|
this.setState({
|
|
|
|
modal: 'notEnoughCredits',
|
|
|
|
});
|
2016-08-07 22:10:44 +02:00
|
|
|
} else {
|
|
|
|
window.location = '?watch=' + this.props.streamName;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2016-10-21 09:53:45 +02:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
modal: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
closeModal: function() {
|
|
|
|
this.setState({
|
|
|
|
modal: null,
|
|
|
|
});
|
|
|
|
},
|
2016-08-07 22:10:44 +02:00
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
icon: 'icon-play',
|
|
|
|
label: 'Watch',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
2016-10-21 09:53:45 +02:00
|
|
|
return (
|
2016-10-28 14:51:15 +02:00
|
|
|
<span className="button-container">
|
2016-10-21 09:53:45 +02:00
|
|
|
<Link button={this.props.button} hidden={this.props.hidden} style={this.props.style}
|
|
|
|
label={this.props.label} icon={this.props.icon} onClick={this.handleClick} />
|
|
|
|
<Modal isOpen={this.state.modal == 'notEnoughCredits'} onConfirmed={this.closeModal}>
|
|
|
|
You don't have enough LBRY credits to pay for this stream.
|
|
|
|
</Modal>
|
2016-10-22 09:38:39 +02:00
|
|
|
</span>
|
2016-10-21 09:53:45 +02:00
|
|
|
);
|
2016-08-07 22:10:44 +02:00
|
|
|
}
|
|
|
|
});
|