2017-04-23 11:56:50 +02:00
|
|
|
import React from 'react';
|
|
|
|
import lbry from 'lbry.js';
|
|
|
|
import lbryuri from 'lbryuri.js';
|
|
|
|
import Link from 'component/link';
|
2017-04-29 11:50:29 +02:00
|
|
|
import FileActions from 'component/fileActions';
|
2017-04-29 19:02:25 +02:00
|
|
|
import {Thumbnail, TruncatedText,} from 'component/common.js';
|
|
|
|
import FilePrice from 'component/filePrice'
|
2017-05-02 07:25:31 +02:00
|
|
|
import UriIndicator from 'component/uriIndicator';
|
2017-04-23 11:56:50 +02:00
|
|
|
|
|
|
|
/*should be merged into FileTile once FileTile is refactored to take a single id*/
|
2017-04-29 11:50:29 +02:00
|
|
|
class FileTileStream extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this._fileInfoSubscribeId = null
|
|
|
|
this._isMounted = null
|
|
|
|
this.state = {
|
2017-04-23 11:56:50 +02:00
|
|
|
showNsfwHelp: false,
|
|
|
|
isHidden: false,
|
|
|
|
}
|
2017-04-29 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2017-04-23 11:56:50 +02:00
|
|
|
this._isMounted = true;
|
|
|
|
if (this.props.hideOnRemove) {
|
|
|
|
this._fileInfoSubscribeId = lbry.fileInfoSubscribe(this.props.outpoint, this.onFileInfoUpdate);
|
|
|
|
}
|
2017-04-29 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2017-04-23 11:56:50 +02:00
|
|
|
if (this._fileInfoSubscribeId) {
|
|
|
|
lbry.fileInfoUnsubscribe(this.props.outpoint, this._fileInfoSubscribeId);
|
|
|
|
}
|
2017-04-29 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onFileInfoUpdate(fileInfo) {
|
2017-04-23 11:56:50 +02:00
|
|
|
if (!fileInfo && this._isMounted && this.props.hideOnRemove) {
|
|
|
|
this.setState({
|
|
|
|
isHidden: true
|
|
|
|
});
|
|
|
|
}
|
2017-04-29 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handleMouseOver() {
|
2017-04-23 11:56:50 +02:00
|
|
|
if (this.props.obscureNsfw && this.props.metadata && this.props.metadata.nsfw) {
|
|
|
|
this.setState({
|
|
|
|
showNsfwHelp: true,
|
|
|
|
});
|
|
|
|
}
|
2017-04-29 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handleMouseOut() {
|
2017-04-23 11:56:50 +02:00
|
|
|
if (this.state.showNsfwHelp) {
|
|
|
|
this.setState({
|
|
|
|
showNsfwHelp: false,
|
|
|
|
});
|
|
|
|
}
|
2017-04-29 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-04-23 11:56:50 +02:00
|
|
|
if (this.state.isHidden) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-04-29 11:50:29 +02:00
|
|
|
const {
|
|
|
|
metadata,
|
2017-05-02 08:11:43 +02:00
|
|
|
isResolvingUri,
|
2017-04-29 11:50:29 +02:00
|
|
|
navigate,
|
2017-05-02 08:11:43 +02:00
|
|
|
hidePrice,
|
2017-04-29 11:50:29 +02:00
|
|
|
} = this.props
|
|
|
|
|
2017-04-23 11:56:50 +02:00
|
|
|
const uri = lbryuri.normalize(this.props.uri);
|
|
|
|
const isConfirmed = !!metadata;
|
|
|
|
const title = isConfirmed ? metadata.title : uri;
|
|
|
|
const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw;
|
2017-04-29 11:50:29 +02:00
|
|
|
|
2017-05-02 08:11:43 +02:00
|
|
|
let description = ""
|
|
|
|
if (isConfirmed) {
|
|
|
|
description = metadata.description
|
|
|
|
} else if (isResolvingUri) {
|
|
|
|
description = "Loading..."
|
|
|
|
} else {
|
|
|
|
description = <span className="empty">This file is pending confirmation</span>
|
|
|
|
}
|
2017-05-02 07:25:31 +02:00
|
|
|
|
2017-04-23 11:56:50 +02:00
|
|
|
return (
|
2017-04-29 11:50:29 +02:00
|
|
|
<section className={ 'file-tile card ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseOut.bind(this)}>
|
2017-04-23 11:56:50 +02:00
|
|
|
<div className={"row-fluid card__inner file-tile__row"}>
|
|
|
|
<div className="span3 file-tile__thumbnail-container">
|
2017-04-30 05:19:59 +02:00
|
|
|
<a href="#" onClick={() => navigate(`show=${uri}`)}>
|
|
|
|
{metadata && metadata.thumbnail ?
|
|
|
|
<Thumbnail key={this.props.uri} className="file-tile__thumbnail" src={metadata.thumbnail} alt={'Photo for ' + this.props.uri} />
|
|
|
|
:
|
|
|
|
<Thumbnail className="file-tile__thumbnail" alt={'Photo for ' + this.props.uri} />
|
|
|
|
}
|
|
|
|
</a>
|
2017-04-23 11:56:50 +02:00
|
|
|
</div>
|
|
|
|
<div className="span9">
|
|
|
|
<div className="card__title-primary">
|
|
|
|
{ !this.props.hidePrice
|
|
|
|
? <FilePrice uri={this.props.uri} />
|
|
|
|
: null}
|
2017-05-01 06:51:19 +02:00
|
|
|
<div className="meta"><a href="#" onClick={() => navigate(`show=${uri}`)}>{uri}</a></div>
|
2017-04-23 11:56:50 +02:00
|
|
|
<h3>
|
2017-05-01 06:51:19 +02:00
|
|
|
<a href="#" onClick={() => navigate(`show=${uri}`)} title={title}>
|
2017-04-23 11:56:50 +02:00
|
|
|
<TruncatedText lines={1}>
|
|
|
|
{title}
|
|
|
|
</TruncatedText>
|
|
|
|
</a>
|
|
|
|
</h3>
|
|
|
|
</div>
|
|
|
|
<div className="card__actions">
|
|
|
|
</div>
|
|
|
|
<div className="card__content">
|
|
|
|
<p className="file-tile__description">
|
2017-05-02 08:11:43 +02:00
|
|
|
<TruncatedText lines={2}>{description}</TruncatedText>
|
2017-04-23 11:56:50 +02:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{this.state.showNsfwHelp
|
|
|
|
? <div className='card-overlay'>
|
|
|
|
<p>
|
|
|
|
This content is Not Safe For Work.
|
2017-05-01 06:51:19 +02:00
|
|
|
To view adult content, please change your <Link className="button-text" href="#" onClick={() => navigate('settings')} label="Settings" />.
|
2017-04-23 11:56:50 +02:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
: null}
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
2017-04-29 11:50:29 +02:00
|
|
|
}
|
2017-04-23 11:56:50 +02:00
|
|
|
|
|
|
|
export default FileTileStream
|