2016-12-23 07:57:01 +01:00
|
|
|
import React from 'react';
|
|
|
|
import lbry from '../lbry.js';
|
2017-01-21 22:31:41 +01:00
|
|
|
import {Link} from '../component/link.js';
|
2017-01-13 03:03:34 +01:00
|
|
|
import {FileActions} from '../component/file-actions.js';
|
2016-12-23 07:57:01 +01:00
|
|
|
import {Thumbnail, TruncatedText, CreditAmount} from '../component/common.js';
|
|
|
|
|
2017-01-13 03:03:34 +01:00
|
|
|
let FilePrice = React.createClass({
|
2017-01-02 08:01:55 +01:00
|
|
|
_isMounted: false,
|
|
|
|
|
2016-12-25 06:12:50 +01:00
|
|
|
propTypes: {
|
2017-01-13 03:03:34 +01:00
|
|
|
name: React.PropTypes.string
|
2016-12-25 06:12:50 +01:00
|
|
|
},
|
2017-01-02 08:01:55 +01:00
|
|
|
|
2017-01-13 03:03:34 +01:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
cost: null,
|
|
|
|
costIncludesData: null,
|
|
|
|
}
|
|
|
|
},
|
2017-01-02 08:01:55 +01:00
|
|
|
|
2017-01-13 03:03:34 +01:00
|
|
|
componentDidMount: function() {
|
|
|
|
this._isMounted = true;
|
2017-01-02 08:01:55 +01:00
|
|
|
|
2017-01-13 03:03:34 +01:00
|
|
|
lbry.getCostInfoForName(this.props.name, ({cost, includesData}) => {
|
|
|
|
if (this._isMounted) {
|
|
|
|
this.setState({
|
|
|
|
cost: cost,
|
|
|
|
costIncludesData: includesData,
|
|
|
|
});
|
|
|
|
}
|
2017-01-25 01:17:00 +01:00
|
|
|
}, () => {
|
|
|
|
// If we get an error looking up cost information, do nothing
|
2017-01-13 03:03:34 +01:00
|
|
|
});
|
|
|
|
},
|
2017-01-06 12:27:43 +01:00
|
|
|
|
2017-01-13 03:03:34 +01:00
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._isMounted = false;
|
2017-01-02 08:01:55 +01:00
|
|
|
},
|
2017-01-13 03:03:34 +01:00
|
|
|
|
|
|
|
render: function() {
|
|
|
|
if (this.state.cost === null)
|
|
|
|
{
|
|
|
|
return null;
|
2017-01-06 12:27:43 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 03:03:34 +01:00
|
|
|
return (
|
|
|
|
<span className="file-tile__cost">
|
|
|
|
<CreditAmount amount={this.state.cost} isEstimate={!this.state.costIncludesData}/>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2017-01-06 12:27:43 +01:00
|
|
|
|
2017-01-13 04:23:12 +01:00
|
|
|
/*should be merged into FileTile once FileTile is refactored to take a single id*/
|
2017-01-13 18:13:46 +01:00
|
|
|
export let FileTileStream = React.createClass({
|
2017-01-13 23:47:48 +01:00
|
|
|
_fileInfoSubscribeId: null,
|
|
|
|
_isMounted: null,
|
|
|
|
|
2017-01-13 03:03:34 +01:00
|
|
|
propTypes: {
|
2017-01-13 04:23:12 +01:00
|
|
|
metadata: React.PropTypes.object,
|
2017-01-13 03:03:34 +01:00
|
|
|
sdHash: React.PropTypes.string,
|
2017-01-13 23:47:48 +01:00
|
|
|
hideOnRemove: React.PropTypes.bool,
|
2017-01-13 18:13:46 +01:00
|
|
|
hidePrice: React.PropTypes.bool,
|
2017-01-13 23:18:37 +01:00
|
|
|
obscureNsfw: React.PropTypes.bool
|
2017-01-06 12:27:43 +01:00
|
|
|
},
|
2016-12-23 07:57:01 +01:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2017-01-13 03:03:34 +01:00
|
|
|
showNsfwHelp: false,
|
2017-01-19 10:58:11 +01:00
|
|
|
isHidden: false,
|
|
|
|
available: null,
|
2016-12-23 07:57:01 +01:00
|
|
|
}
|
|
|
|
},
|
2016-12-25 06:12:50 +01:00
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
2017-01-13 03:03:34 +01:00
|
|
|
obscureNsfw: !lbry.getClientSetting('showNsfw'),
|
2017-01-13 18:13:46 +01:00
|
|
|
hidePrice: false
|
2016-12-25 06:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
2017-01-13 23:47:48 +01:00
|
|
|
componentDidMount: function() {
|
|
|
|
this._isMounted = true;
|
|
|
|
if (this.props.hideOnRemove) {
|
|
|
|
lbry.fileInfoSubscribe(this.props.sdHash, this.onFileInfoUpdate);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
if (this._fileInfoSubscribeId) {
|
|
|
|
lbry.fileInfoUnsubscribe(this.props.sdHash, this._fileInfoSubscribeId);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onFileInfoUpdate: function(fileInfo) {
|
|
|
|
if (!fileInfo && this._isMounted && this.props.hideOnRemove) {
|
|
|
|
this.setState({
|
|
|
|
isHidden: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2016-12-23 07:57:01 +01:00
|
|
|
handleMouseOver: function() {
|
2017-01-13 04:23:12 +01:00
|
|
|
if (this.props.obscureNsfw && this.props.metadata && this.props.metadata.nsfw) {
|
2017-01-13 03:03:34 +01:00
|
|
|
this.setState({
|
|
|
|
showNsfwHelp: true,
|
|
|
|
});
|
|
|
|
}
|
2016-12-23 07:57:01 +01:00
|
|
|
},
|
|
|
|
handleMouseOut: function() {
|
2017-01-13 03:03:34 +01:00
|
|
|
if (this.state.showNsfwHelp) {
|
|
|
|
this.setState({
|
|
|
|
showNsfwHelp: false,
|
|
|
|
});
|
|
|
|
}
|
2016-12-23 07:57:01 +01:00
|
|
|
},
|
|
|
|
render: function() {
|
2017-01-21 07:52:32 +01:00
|
|
|
if (this.state.isHidden) {
|
2017-01-13 23:47:48 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-01-30 08:26:30 +01:00
|
|
|
const metadata = this.props.metadata;
|
|
|
|
const isConfirmed = typeof metadata == 'object';
|
2017-02-01 09:43:19 +01:00
|
|
|
const title = isConfirmed ? metadata.title : ('lbry://' + this.props.name);
|
2017-01-30 08:26:30 +01:00
|
|
|
const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw;
|
2016-12-23 07:57:01 +01:00
|
|
|
return (
|
2017-01-13 03:03:34 +01:00
|
|
|
<section className={ 'file-tile card ' + (obscureNsfw ? 'card-obscured ' : '') } onMouseEnter={this.handleMouseOver} onMouseLeave={this.handleMouseOut}>
|
2017-01-21 07:52:32 +01:00
|
|
|
<div className={"row-fluid card-content file-tile__row"}>
|
2016-12-23 07:57:01 +01:00
|
|
|
<div className="span3">
|
2017-02-21 05:15:17 +01:00
|
|
|
<a href={'/?show=' + this.props.name}><Thumbnail className="file-tile__thumbnail" src={metadata.thumbnail} alt={`Photo for ${title}`} /></a>
|
2016-12-23 07:57:01 +01:00
|
|
|
</div>
|
|
|
|
<div className="span9">
|
2017-01-13 18:13:46 +01:00
|
|
|
{ !this.props.hidePrice
|
2017-01-13 03:03:34 +01:00
|
|
|
? <FilePrice name={this.props.name} />
|
2016-12-23 07:57:01 +01:00
|
|
|
: null}
|
2017-02-21 05:15:17 +01:00
|
|
|
<div className="meta"><a href={'/?show=' + this.props.name}>{'lbry://' + this.props.name}</a></div>
|
2017-01-13 03:03:34 +01:00
|
|
|
<h3 className="file-tile__title">
|
2017-02-21 05:15:17 +01:00
|
|
|
<a href={'/?show=' + this.props.name}>
|
2017-01-13 05:15:44 +01:00
|
|
|
<TruncatedText lines={1}>
|
2017-01-13 04:23:12 +01:00
|
|
|
{title}
|
2016-12-23 07:57:01 +01:00
|
|
|
</TruncatedText>
|
|
|
|
</a>
|
|
|
|
</h3>
|
2017-01-13 23:18:37 +01:00
|
|
|
<FileActions streamName={this.props.name} sdHash={this.props.sdHash} metadata={metadata} />
|
2016-12-23 07:57:01 +01:00
|
|
|
<p className="file-tile__description">
|
|
|
|
<TruncatedText lines={3}>
|
2017-01-30 08:26:30 +01:00
|
|
|
{isConfirmed
|
|
|
|
? metadata.description
|
|
|
|
: <span className="empty">This file is pending confirmation.</span>}
|
2016-12-23 07:57:01 +01:00
|
|
|
</TruncatedText>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-01-13 03:03:34 +01:00
|
|
|
{this.state.showNsfwHelp
|
2016-12-23 08:02:05 +01:00
|
|
|
? <div className='card-overlay'>
|
2017-01-13 04:23:12 +01:00
|
|
|
<p>
|
|
|
|
This content is Not Safe For Work.
|
2017-01-25 04:22:36 +01:00
|
|
|
To view adult content, please change your <Link className="button-text" href="?settings" label="Settings" />.
|
2017-01-13 04:23:12 +01:00
|
|
|
</p>
|
|
|
|
</div>
|
2016-12-23 08:02:05 +01:00
|
|
|
: null}
|
2016-12-23 07:57:01 +01:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-01-13 18:13:46 +01:00
|
|
|
export let FileTile = React.createClass({
|
2017-01-13 04:23:12 +01:00
|
|
|
_isMounted: false,
|
|
|
|
|
|
|
|
propTypes: {
|
2017-01-19 10:58:11 +01:00
|
|
|
name: React.PropTypes.string.isRequired,
|
|
|
|
available: React.PropTypes.bool,
|
2017-01-13 04:23:12 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
sdHash: null,
|
|
|
|
metadata: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
|
|
|
this._isMounted = true;
|
|
|
|
|
|
|
|
lbry.resolveName(this.props.name, (metadata) => {
|
2017-02-20 00:45:03 +01:00
|
|
|
if (this._isMounted && metadata) {
|
|
|
|
// In case of a failed lookup, metadata will be null, in which case the component will never display
|
2017-01-13 04:23:12 +01:00
|
|
|
this.setState({
|
|
|
|
sdHash: metadata.sources.lbry_sd_hash,
|
|
|
|
metadata: metadata,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._isMounted = false;
|
|
|
|
},
|
|
|
|
render: function() {
|
2017-01-13 23:18:37 +01:00
|
|
|
if (!this.state.metadata || !this.state.sdHash) {
|
2017-01-13 04:23:12 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-01-20 14:49:47 +01:00
|
|
|
return <FileTileStream sdHash={this.state.sdHash} metadata={this.state.metadata} {... this.props} />;
|
2017-01-13 04:23:12 +01:00
|
|
|
}
|
2017-02-21 05:15:17 +01:00
|
|
|
});
|