import React from 'react'; import lbry from '../lbry.js'; import Modal from './modal.js'; import {Icon, ToolTip} from './common.js'; export let Link = React.createClass({ propTypes: { label: React.PropTypes.string, icon: React.PropTypes.string, button: React.PropTypes.string, badge: React.PropTypes.string, hidden: React.PropTypes.bool, }, getDefaultProps: function() { return { hidden: false, disabled: false, }; }, handleClick: function() { if (this.props.onClick) { this.props.onClick(); } }, render: function() { if (this.props.hidden) { return null; } const className = (this.props.className || '') + (this.props.button ? ' button-block button-' + this.props.button : '') + (!this.props.className && !this.props.button ? 'button-text' : '') + (this.props.disabled ? ' disabled' : ''); return ( {'icon' in this.props ? : null} {this.props.label} {'badge' in this.props ? {this.props.badge} : null} ); } }); var linkContainerStyle = { position: 'relative', }; export let ToolTipLink = React.createClass({ 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 ? : '', className = this.props.className + (this.props.button ? ' button-block button-' + this.props.button : '') + (this.props.hidden ? ' hidden' : '') + (this.props.disabled ? ' disabled' : ''); return ( {this.props.icon ? icon : '' } {this.props.label} {(!this.props.tooltip ? null : {this.props.tooltip} )} ); } }); export let DownloadLink = React.createClass({ propTypes: { type: React.PropTypes.string, streamName: React.PropTypes.string, sdHash: React.PropTypes.string, label: React.PropTypes.string, button: React.PropTypes.string, state: React.PropTypes.oneOf(['not-started', 'downloading', 'done']), progress: React.PropTypes.number, path: React.PropTypes.string, hidden: React.PropTypes.bool, }, tryDownload: function() { lbry.getCostInfoForName(this.props.streamName, ({cost}) => { lbry.getBalance((balance) => { if (cost > balance) { this.setState({ modal: 'notEnoughCredits', }); } else { lbry.getStream(this.props.streamName, (streamInfo) => { if (streamInfo === null || typeof streamInfo !== 'object') { this.setState({ modal: 'timedOut', }); } else { this.setState({ modal: 'downloadStarted', filePath: streamInfo.path, }); } }); } }); }); }, getDefaultProps: function() { return { state: 'not-started', } }, getInitialState: function() { return { filePath: null, modal: null, } }, closeModal: function() { this.setState({ modal: null, }) }, handleClick: function() { if (this.props.state == 'not-started') { this.tryDownload(); } else if (this.props.state == 'done') { lbry.revealFile(this.props.path); } }, render: function() { let linkBlock; if (this.props.state == 'not-started') { linkBlock = ( ); } else if (this.props.state == 'downloading') { const label = `${parseInt(this.props.progress * 100)}% complete`; linkBlock = ( ); } else if (this.props.state == 'done') { linkBlock = ( ); } else { throw new Error(`Unknown download state ${this.props.state} passed to DownloadLink`); } return ( {'progress' in this.props ? : null}

Downloading to:

{this.state.filePath}
You don't have enough LBRY credits to pay for this stream. LBRY was unable to download the stream lbry://{this.props.streamName}.
); } }); export let WatchLink = React.createClass({ propTypes: { type: React.PropTypes.string, streamName: React.PropTypes.string, label: React.PropTypes.string, button: React.PropTypes.string, hidden: React.PropTypes.bool, }, handleClick: function() { this.setState({ loading: true, }) lbry.getCostInfoForName(this.props.streamName, ({cost}) => { lbry.getBalance((balance) => { if (cost > balance) { this.setState({ modal: 'notEnoughCredits', loading: false, }); } else { window.location = '?watch=' + this.props.streamName; } }); }); }, getInitialState: function() { return { modal: null, loading: false, }; }, closeModal: function() { this.setState({ modal: null, }); }, getDefaultProps: function() { return { icon: 'icon-play', label: 'Watch', } }, render: function() { return (
You don't have enough LBRY credits to pay for this stream.
); } });