2016-04-10 02:00:56 +02:00
|
|
|
//component/icon.js
|
|
|
|
|
|
|
|
var Icon = React.createClass({
|
2016-04-15 12:41:01 +02:00
|
|
|
propTypes: {
|
|
|
|
style: React.PropTypes.object,
|
2016-05-27 13:07:21 +02:00
|
|
|
fixed: React.PropTypes.boolean,
|
2016-04-15 12:41:01 +02:00
|
|
|
},
|
2016-04-10 02:00:56 +02:00
|
|
|
render: function() {
|
2016-05-27 13:07:21 +02:00
|
|
|
var className = 'icon ' + ('fixed' in this.props ? 'icon-fixed-width ' : '') + this.props.icon;
|
2016-04-15 12:41:01 +02:00
|
|
|
return <span className={className} style={this.props.style}></span>
|
2016-04-10 02:00:56 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-07-26 14:01:54 +02:00
|
|
|
var toolTipStyle = {
|
|
|
|
position: 'absolute',
|
2016-07-27 12:24:10 +02:00
|
|
|
zIndex: '1',
|
2016-07-26 14:01:54 +02:00
|
|
|
top: '100%',
|
|
|
|
left: '-120px',
|
|
|
|
width: '260px',
|
|
|
|
padding: '15px',
|
|
|
|
border: '1px solid #aaa',
|
2016-07-27 12:24:10 +02:00
|
|
|
backgroundColor: '#fff',
|
2016-07-26 14:01:54 +02:00
|
|
|
fontSize: '14px',
|
|
|
|
};
|
|
|
|
var ToolTip = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
open: React.PropTypes.bool.isRequired,
|
|
|
|
onMouseOut: React.PropTypes.func
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<div className={this.props.open ? '' : 'hidden'} style={toolTipStyle} onMouseOut={this.props.onMouseOut}>
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var linkContainerStyle = {
|
|
|
|
position: 'relative',
|
|
|
|
};
|
2016-04-10 02:00:56 +02:00
|
|
|
var Link = React.createClass({
|
2016-07-26 14:01:54 +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,
|
|
|
|
});
|
|
|
|
},
|
2016-04-10 02:00:56 +02:00
|
|
|
render: function() {
|
|
|
|
var href = this.props.href ? this.props.href : 'javascript:;',
|
|
|
|
icon = this.props.icon ? <Icon icon={this.props.icon} /> : '',
|
2016-04-20 13:51:31 +02:00
|
|
|
className = (this.props.button ? 'button-block button-' + this.props.button : 'button-text') +
|
2016-04-21 12:55:41 +02:00
|
|
|
(this.props.hidden ? ' hidden' : '') + (this.props.disabled ? ' disabled' : '');
|
2016-07-26 14:01:54 +02:00
|
|
|
|
|
|
|
|
2016-04-10 02:00:56 +02:00
|
|
|
return (
|
2016-07-26 14:01:54 +02:00
|
|
|
<span style={linkContainerStyle}>
|
|
|
|
<a className={className} href={href} style={this.props.style ? this.props.style : {}}
|
|
|
|
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>
|
2016-04-10 02:00:56 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-18 14:28:13 +02:00
|
|
|
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-08-02 11:12:52 +02:00
|
|
|
handleClick: function() {
|
|
|
|
lbry.getCostEstimate(this.props.streamName, (amount) => {
|
|
|
|
lbry.getBalance((balance) => {
|
|
|
|
if (amount > balance) {
|
|
|
|
alert("You don't have enough LBRY credits to pay for this stream.");
|
|
|
|
} else {
|
|
|
|
this.startDownload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2016-05-18 14:28:13 +02:00
|
|
|
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) => {
|
|
|
|
alert('Downloading to ' + streamInfo.path);
|
|
|
|
console.log(streamInfo);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var label = (!this.state.downloading ? this.props.label : this.props.downloadingLabel);
|
|
|
|
return <Link button={this.props.button} hidden={this.props.hidden} style={this.props.style}
|
2016-08-02 11:12:52 +02:00
|
|
|
disabled={this.state.downloading} label={label} icon={this.props.icon} onClick={this.handleClick} />;
|
2016-05-18 14:28:13 +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,
|
|
|
|
},
|
2016-08-02 11:12:52 +02:00
|
|
|
handleClick: function() {
|
|
|
|
lbry.getCostEstimate(this.props.streamName, (amount) => {
|
|
|
|
lbry.getBalance((balance) => {
|
|
|
|
if (amount > balance) {
|
|
|
|
alert("You don't have enough LBRY credits to pay for this stream.");
|
|
|
|
} else {
|
|
|
|
window.location = '?watch=' + this.props.streamName;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2016-05-18 14:28:13 +02:00
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
icon: 'icon-play',
|
|
|
|
label: 'Watch',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-08-02 11:12:52 +02:00
|
|
|
render: function() {
|
2016-05-18 14:28:13 +02:00
|
|
|
return <Link button={this.props.button} hidden={this.props.hidden} style={this.props.style}
|
2016-08-02 11:12:52 +02:00
|
|
|
label={this.props.label} icon={this.props.icon} onClick={this.handleClick} />;
|
2016-05-18 14:28:13 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-07-26 12:07:56 +02:00
|
|
|
var requiredFieldWarningStyle = {
|
|
|
|
color: '#cc0000',
|
|
|
|
transition: 'opacity 400ms ease-in',
|
|
|
|
};
|
|
|
|
var FormField = React.createClass({
|
|
|
|
_type: null,
|
|
|
|
_element: null,
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
type: React.PropTypes.string.isRequired,
|
|
|
|
hidden: React.PropTypes.bool,
|
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
warningState: 'hidden',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
componentWillMount: function() {
|
2016-07-27 17:54:09 +02:00
|
|
|
if (['text', 'radio', 'checkbox', 'file'].indexOf(this.props.type) != -1) {
|
2016-07-26 12:07:56 +02:00
|
|
|
this._element = 'input';
|
|
|
|
this._type = this.props.type;
|
|
|
|
} else {
|
|
|
|
// Non <input> field, e.g. <select>, <textarea>
|
|
|
|
this._element = this.props.type;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
warnRequired: function() {
|
|
|
|
this.setState({
|
|
|
|
warningState: 'shown',
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setState({
|
|
|
|
warningState: 'fading',
|
|
|
|
});
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setState({
|
|
|
|
warningState: 'hidden',
|
|
|
|
});
|
|
|
|
}, 450);
|
|
|
|
}, 5000);
|
|
|
|
},
|
|
|
|
focus: function() {
|
|
|
|
this.refs.field.focus();
|
|
|
|
},
|
|
|
|
getValue: function() {
|
2016-07-27 17:54:09 +02:00
|
|
|
if (this.props.type == 'checkbox') {
|
|
|
|
return this.refs.field.checked;
|
|
|
|
} else {
|
|
|
|
return this.refs.field.value;
|
|
|
|
}
|
2016-07-26 12:07:56 +02:00
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var warningStyle = Object.assign({}, requiredFieldWarningStyle);
|
|
|
|
if (this.state.warningState == 'fading') {
|
|
|
|
warningStyle.opacity = '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass all unhandled props to the field element
|
|
|
|
var otherProps = Object.assign({}, this.props);
|
|
|
|
delete otherProps.type;
|
|
|
|
delete otherProps.hidden;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className={this.props.hidden ? 'hidden' : ''}>
|
|
|
|
<this._element type={this._type} name={this.props.name} ref="field" placeholder={this.props.placeholder}
|
|
|
|
{...otherProps}>
|
|
|
|
{this.props.children}
|
|
|
|
</this._element>
|
|
|
|
<span className={this.state.warningState == 'hidden' ? 'hidden' : ''} style={warningStyle}> This field is required</span>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-27 13:07:21 +02:00
|
|
|
// Generic menu styles
|
|
|
|
var menuStyle = {
|
|
|
|
border: '1px solid #aaa',
|
2016-05-28 09:08:34 +02:00
|
|
|
padding: '4px',
|
2016-05-27 13:07:21 +02:00
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
};
|
|
|
|
|
|
|
|
var Menu = React.createClass({
|
2016-05-28 12:22:09 +02:00
|
|
|
handleWindowClick: function(e) {
|
|
|
|
if (this.props.toggleButton && ReactDOM.findDOMNode(this.props.toggleButton).contains(e.target)) {
|
|
|
|
// Toggle button was clicked
|
|
|
|
this.setState({
|
|
|
|
open: !this.state.open
|
|
|
|
});
|
|
|
|
} else if (this.state.open && !this.refs.div.contains(e.target)) {
|
|
|
|
// Menu is open and user clicked outside of it
|
|
|
|
this.setState({
|
|
|
|
open: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
propTypes: {
|
|
|
|
openButton: React.PropTypes.element,
|
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
open: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
componentDidMount: function() {
|
|
|
|
window.addEventListener('click', this.handleWindowClick, false);
|
|
|
|
},
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
window.removeEventListener('click', this.handleWindowClick, false);
|
|
|
|
},
|
2016-05-27 13:07:21 +02:00
|
|
|
render: function() {
|
|
|
|
return (
|
2016-05-29 11:28:06 +02:00
|
|
|
<div ref='div' style={menuStyle} className={this.state.open ? '' : 'hidden'}>
|
2016-05-27 13:07:21 +02:00
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var menuItemStyle = {
|
|
|
|
display: 'block',
|
|
|
|
};
|
|
|
|
var MenuItem = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
href: React.PropTypes.string,
|
|
|
|
label: React.PropTypes.string,
|
|
|
|
icon: React.PropTypes.string,
|
|
|
|
onClick: React.PropTypes.function,
|
|
|
|
},
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
iconPosition: 'left',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var icon = (this.props.icon ? <Icon icon={this.props.icon} fixed /> : null);
|
|
|
|
|
|
|
|
return (
|
2016-05-29 13:04:25 +02:00
|
|
|
<a style={menuItemStyle} className="button-text no-underline" onClick={this.props.onClick}
|
|
|
|
href={this.props.href || 'javascript:'} label={this.props.label}>
|
2016-05-27 13:07:21 +02:00
|
|
|
{this.props.iconPosition == 'left' ? icon : null}
|
|
|
|
{this.props.label}
|
|
|
|
{this.props.iconPosition == 'left' ? null : icon}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-10 02:00:56 +02:00
|
|
|
var creditAmountStyle = {
|
|
|
|
color: '#216C2A',
|
|
|
|
fontWeight: 'bold',
|
|
|
|
fontSize: '0.8em'
|
|
|
|
}, estimateStyle = {
|
|
|
|
marginLeft : '5px',
|
|
|
|
color: '#aaa',
|
|
|
|
};
|
|
|
|
|
|
|
|
var CreditAmount = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
amount: React.PropTypes.number,
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var formattedAmount = lbry.formatCredits(this.props.amount);
|
|
|
|
return (
|
|
|
|
<span className="credit-amount">
|
|
|
|
<span style={creditAmountStyle}>{formattedAmount}</span>
|
|
|
|
{ this.props.isEstimate ? <span style={estimateStyle}>(est)</span> : null }
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
2016-05-23 16:24:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
var subPageLogoStyle = {
|
|
|
|
maxWidth: '150px',
|
|
|
|
display: 'block',
|
|
|
|
marginTop: '36px',
|
|
|
|
};
|
2016-05-28 12:22:09 +02:00
|
|
|
|
2016-05-23 16:24:23 +02:00
|
|
|
var SubPageLogo = React.createClass({
|
|
|
|
render: function() {
|
|
|
|
return <img src="img/lbry-dark-1600x528.png" style={subPageLogoStyle} />;
|
|
|
|
}
|
2016-04-10 02:00:56 +02:00
|
|
|
});
|