2016-11-22 21:19:08 +01:00
|
|
|
import React from 'react';
|
|
|
|
import lbry from '../lbry.js';
|
2017-01-09 11:48:04 +01:00
|
|
|
import FormField from './form.js';
|
2016-11-22 21:19:08 +01:00
|
|
|
import Modal from './modal.js';
|
2017-01-09 11:48:04 +01:00
|
|
|
import {Menu, MenuItem} from './menu.js';
|
2016-11-22 21:19:08 +01:00
|
|
|
import {Icon, ToolTip} from './common.js';
|
|
|
|
|
|
|
|
|
|
|
|
export let Link = React.createClass({
|
2017-01-09 05:56:21 +01:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
},
|
2016-08-07 22:36:57 +02:00
|
|
|
handleClick: function() {
|
|
|
|
if (this.props.onClick) {
|
|
|
|
this.props.onClick();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
2017-01-09 05:56:21 +01:00
|
|
|
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' : '');
|
2016-08-07 22:36:57 +02:00
|
|
|
|
2017-01-09 11:43:57 +01:00
|
|
|
let content;
|
|
|
|
if (this.props.children) { // Custom content
|
|
|
|
content = this.props.children;
|
|
|
|
} else {
|
|
|
|
content = (
|
|
|
|
<span>
|
|
|
|
{'icon' in this.props
|
|
|
|
? <Icon icon={this.props.icon} fixed={true} />
|
|
|
|
: null}
|
|
|
|
<span className="link-label">{this.props.label}</span>
|
|
|
|
{'badge' in this.props
|
|
|
|
? <span className="badge">{this.props.badge}</span>
|
|
|
|
: null}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-08-07 22:36:57 +02:00
|
|
|
return (
|
2017-01-09 05:56:21 +01:00
|
|
|
<a className={className} href={this.props.href || 'javascript:;'} title={this.props.title}
|
|
|
|
onClick={this.handleClick} {... 'style' in this.props ? {style: this.props.style} : {}}>
|
2017-01-09 11:43:57 +01:00
|
|
|
{content}
|
2016-08-07 22:36:57 +02:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-07 22:10:44 +02:00
|
|
|
var linkContainerStyle = {
|
|
|
|
position: 'relative',
|
|
|
|
};
|
|
|
|
|
2016-11-22 21:19:08 +01:00
|
|
|
export let 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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-01-09 11:48:04 +01:00
|
|
|
export let DropDown = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
onCaretClick: React.PropTypes.func,
|
|
|
|
},
|
|
|
|
handleCaretClicked: function(event) {
|
|
|
|
/**
|
|
|
|
* The menu handles caret clicks via a window event listener, so we just need to prevent clicks
|
|
|
|
* on the caret from bubbling up to the link
|
|
|
|
*/
|
|
|
|
this.setState({
|
|
|
|
menuOpen: !this.state.menuOpen,
|
|
|
|
});
|
|
|
|
event.stopPropagation();
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
closeMenu: function(event) {
|
|
|
|
this.setState({
|
|
|
|
menuOpen: false,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
menuOpen: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
const {onCaretClick, ...other} = this.props;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Link {...other}>
|
|
|
|
<span className="link-label">{this.props.label}</span>
|
2017-01-11 07:41:27 +01:00
|
|
|
<Icon icon="icon-caret-down" fixed={true} onClick={this.handleCaretClicked} />
|
2017-01-09 11:48:04 +01:00
|
|
|
</Link>
|
|
|
|
{this.state.menuOpen
|
|
|
|
? <Menu onClickOut={this.closeMenu}>
|
|
|
|
{this.props.children}
|
|
|
|
</Menu>
|
|
|
|
: null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-22 21:19:08 +01:00
|
|
|
export let DownloadLink = React.createClass({
|
2016-08-07 22:10:44 +02:00
|
|
|
propTypes: {
|
|
|
|
type: React.PropTypes.string,
|
|
|
|
streamName: React.PropTypes.string,
|
2017-01-02 05:29:11 +01:00
|
|
|
sdHash: React.PropTypes.string,
|
2017-01-09 11:48:04 +01:00
|
|
|
metadata: React.PropTypes.object,
|
2016-08-07 22:10:44 +02:00
|
|
|
label: React.PropTypes.string,
|
|
|
|
button: React.PropTypes.string,
|
2017-01-06 12:27:23 +01:00
|
|
|
state: React.PropTypes.oneOf(['not-started', 'downloading', 'done']),
|
|
|
|
progress: React.PropTypes.number,
|
|
|
|
path: React.PropTypes.string,
|
2016-08-07 22:10:44 +02:00
|
|
|
hidden: React.PropTypes.bool,
|
2017-01-09 11:48:04 +01:00
|
|
|
deleteChecked: React.PropTypes.bool,
|
2016-08-07 22:10:44 +02:00
|
|
|
},
|
2017-01-06 12:27:23 +01:00
|
|
|
tryDownload: function() {
|
2017-01-10 08:40:10 +01:00
|
|
|
this.setState({
|
|
|
|
attemptingDownload: true,
|
|
|
|
});
|
2016-12-16 23:56:53 +01:00
|
|
|
lbry.getCostInfoForName(this.props.streamName, ({cost}) => {
|
2016-11-24 05:19:06 +01:00
|
|
|
lbry.getBalance((balance) => {
|
2016-12-16 23:56:53 +01:00
|
|
|
if (cost > balance) {
|
2016-11-24 05:19:06 +01:00
|
|
|
this.setState({
|
|
|
|
modal: 'notEnoughCredits',
|
2017-01-10 08:40:10 +01:00
|
|
|
attemptingDownload: false,
|
2016-11-24 05:19:06 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
lbry.getStream(this.props.streamName, (streamInfo) => {
|
2016-12-16 23:59:12 +01:00
|
|
|
if (streamInfo === null || typeof streamInfo !== 'object') {
|
2016-11-24 05:49:19 +01:00
|
|
|
this.setState({
|
|
|
|
modal: 'timedOut',
|
2017-01-10 08:40:10 +01:00
|
|
|
attemptingDownload: false,
|
2016-11-24 05:49:19 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
filePath: streamInfo.path,
|
2017-01-10 08:40:10 +01:00
|
|
|
attemptingDownload: false,
|
2016-11-24 05:49:19 +01:00
|
|
|
});
|
|
|
|
}
|
2016-11-24 05:19:06 +01:00
|
|
|
});
|
|
|
|
}
|
2016-08-07 22:10:44 +02:00
|
|
|
});
|
2016-11-24 05:19:06 +01:00
|
|
|
});
|
2016-08-07 22:10:44 +02:00
|
|
|
},
|
2017-01-09 11:48:04 +01:00
|
|
|
openMenu: function() {
|
|
|
|
this.setState({
|
|
|
|
menuOpen: !this.state.menuOpen,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleDeleteCheckboxClicked: function(event) {
|
|
|
|
this.setState({
|
|
|
|
deleteChecked: event.target.checked,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleRevealClicked: function() {
|
|
|
|
lbry.revealFile(this.props.path);
|
|
|
|
},
|
|
|
|
handleRemoveClicked: function() {
|
|
|
|
this.setState({
|
|
|
|
modal: 'confirmRemove',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleRemoveConfirmed: function() {
|
|
|
|
lbry.deleteFile(this.props.sdHash || this.props.streamName, this.state.deleteChecked);
|
|
|
|
this.setState({
|
|
|
|
modal: null,
|
|
|
|
});
|
|
|
|
},
|
2017-01-06 12:27:23 +01:00
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
state: 'not-started',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
filePath: null,
|
|
|
|
modal: null,
|
2017-01-09 11:48:04 +01:00
|
|
|
menuOpen: false,
|
2017-01-10 07:28:21 +01:00
|
|
|
deleteChecked: false,
|
2017-01-10 08:40:10 +01:00
|
|
|
attemptingDownload: false,
|
2017-01-06 12:27:23 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
2016-08-07 22:10:44 +02:00
|
|
|
render: function() {
|
2017-01-10 08:15:12 +01:00
|
|
|
const openInFolderMessage = window.navigator.platform.startsWith('Mac') ? 'Open in Finder' : 'Open in Folder';
|
|
|
|
|
|
|
|
const dropDownItems = [
|
|
|
|
<MenuItem onClick={this.handleRevealClicked} label={openInFolderMessage} />,
|
|
|
|
<MenuItem onClick={this.handleRemoveClicked} label="Remove..." />,
|
|
|
|
];
|
|
|
|
|
2017-01-06 12:27:23 +01:00
|
|
|
let linkBlock;
|
2017-01-11 07:41:27 +01:00
|
|
|
if (this.state.attemptingDownload) {
|
|
|
|
linkBlock = <Link button="text" className="button-download button-download--bg"
|
|
|
|
label="Connecting..." icon="icon-download" />
|
|
|
|
} else if (this.props.state == 'downloading') {
|
|
|
|
const label = `${parseInt(this.props.progress * 100)}% complete`;
|
2017-01-06 12:27:23 +01:00
|
|
|
linkBlock = (
|
|
|
|
<span>
|
2017-01-10 08:15:12 +01:00
|
|
|
<DropDown button="download" className="button-download--bg" label={label} icon="icon-download"
|
2017-01-11 07:41:27 +01:00
|
|
|
onClick={this.handleClick}>
|
2017-01-10 08:15:12 +01:00
|
|
|
{dropDownItems}
|
|
|
|
</DropDown>
|
|
|
|
<DropDown button="download" className="button-download--fg" label={label} icon="icon-download"
|
2017-01-11 07:41:27 +01:00
|
|
|
onClick={this.handleClick} style={{width: `${this.props.progress * 100}%`}}>
|
2017-01-10 08:15:12 +01:00
|
|
|
{dropDownItems}
|
|
|
|
</DropDown>
|
|
|
|
</span>
|
2017-01-06 12:27:23 +01:00
|
|
|
);
|
2017-01-10 08:40:10 +01:00
|
|
|
} else if (this.props.state == 'not-started') {
|
|
|
|
linkBlock = (
|
|
|
|
<Link button="text" label="Download" icon="icon-download" onClick={this.handleClick} />
|
|
|
|
);
|
2017-01-06 12:27:23 +01:00
|
|
|
} else if (this.props.state == 'done') {
|
|
|
|
linkBlock = (
|
2017-01-09 11:48:04 +01:00
|
|
|
<DropDown button="alt" label="Open" onClick={this.handleClick} onCaretClick={this.openMenu}>
|
2017-01-10 08:15:12 +01:00
|
|
|
{dropDownItems}
|
2017-01-09 11:48:04 +01:00
|
|
|
</DropDown>
|
2017-01-06 12:27:23 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
throw new Error(`Unknown download state ${this.props.state} passed to DownloadLink`);
|
|
|
|
}
|
|
|
|
|
2016-10-21 09:53:45 +02:00
|
|
|
return (
|
2016-10-28 14:51:15 +02:00
|
|
|
<span className="button-container">
|
2017-01-13 23:05:09 +01:00
|
|
|
<Modal isOpen={this.state.modal == 'notEnoughCredits'} contentLabel="Not enough credits"
|
|
|
|
onConfirmed={this.closeModal}>
|
2016-10-21 09:53:45 +02:00
|
|
|
You don't have enough LBRY credits to pay for this stream.
|
|
|
|
</Modal>
|
2017-01-13 23:05:09 +01:00
|
|
|
<Modal isOpen={this.state.modal == 'timedOut'} contentLabel="Download failed"
|
|
|
|
onConfirmed={this.closeModal}>
|
2016-11-24 05:49:19 +01:00
|
|
|
LBRY was unable to download the stream <strong>lbry://{this.props.streamName}</strong>.
|
|
|
|
</Modal>
|
2017-01-09 11:48:04 +01:00
|
|
|
<Modal isOpen={this.state.modal == 'confirmRemove'} type="confirm" confirmButtonLabel="Remove"
|
|
|
|
onConfirmed={this.handleRemoveConfirmed} onAborted={this.closeModal}>
|
|
|
|
<p>Are you sure you'd like to remove <cite>{this.props.metadata.title}</cite> from LBRY?</p>
|
|
|
|
|
|
|
|
<label><FormField type="checkbox" checked={this.state.deleteChecked} onClick={this.handleDeleteCheckboxClicked} /> Delete this file from my computer</label>
|
|
|
|
</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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-22 21:19:08 +01:00
|
|
|
export let WatchLink = React.createClass({
|
2016-08-07 22:10:44 +02:00
|
|
|
propTypes: {
|
|
|
|
type: React.PropTypes.string,
|
|
|
|
streamName: React.PropTypes.string,
|
|
|
|
label: React.PropTypes.string,
|
|
|
|
button: React.PropTypes.string,
|
|
|
|
hidden: React.PropTypes.bool,
|
|
|
|
},
|
|
|
|
handleClick: function() {
|
2016-11-24 05:30:59 +01:00
|
|
|
this.setState({
|
|
|
|
loading: true,
|
|
|
|
})
|
2016-12-16 23:56:53 +01:00
|
|
|
lbry.getCostInfoForName(this.props.streamName, ({cost}) => {
|
2016-08-07 22:10:44 +02:00
|
|
|
lbry.getBalance((balance) => {
|
2016-12-16 23:56:53 +01:00
|
|
|
if (cost > balance) {
|
2016-10-21 09:53:45 +02:00
|
|
|
this.setState({
|
|
|
|
modal: 'notEnoughCredits',
|
2016-11-24 05:30:59 +01:00
|
|
|
loading: false,
|
2016-10-21 09:53:45 +02:00
|
|
|
});
|
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,
|
2016-11-24 05:30:59 +01:00
|
|
|
loading: false,
|
2016-10-21 09:53:45 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
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 (
|
2017-01-02 05:29:11 +01:00
|
|
|
<div className="button-container">
|
2016-10-21 09:53:45 +02:00
|
|
|
<Link button={this.props.button} hidden={this.props.hidden} style={this.props.style}
|
2016-11-24 05:30:59 +01:00
|
|
|
disabled={this.state.loading} label={this.props.label} icon={this.props.icon}
|
|
|
|
onClick={this.handleClick} />
|
2017-01-13 23:05:09 +01:00
|
|
|
<Modal isOpen={this.state.modal == 'notEnoughCredits'} contentLabel="Not enough credits"
|
|
|
|
onConfirmed={this.closeModal}>
|
2016-10-21 09:53:45 +02:00
|
|
|
You don't have enough LBRY credits to pay for this stream.
|
|
|
|
</Modal>
|
2017-01-02 05:29:11 +01:00
|
|
|
</div>
|
2016-10-21 09:53:45 +02:00
|
|
|
);
|
2016-08-07 22:10:44 +02:00
|
|
|
}
|
2016-11-22 21:19:08 +01:00
|
|
|
});
|