2016-12-23 07:57:01 +01:00
|
|
|
import React from 'react';
|
2017-04-23 11:56:50 +02:00
|
|
|
import lbry from 'lbry.js';
|
|
|
|
import lbryuri from 'lbryuri.js';
|
2017-04-07 07:15:22 +02:00
|
|
|
import Link from 'component/link';
|
2017-04-23 16:01:00 +02:00
|
|
|
import FileActions from 'component/fileActions';
|
2017-05-09 00:22:27 +02:00
|
|
|
import {Thumbnail, TruncatedText,} from 'component/common.js';
|
|
|
|
import FilePrice from 'component/filePrice'
|
|
|
|
import UriIndicator from 'component/uriIndicator';
|
2017-04-23 16:01:00 +02:00
|
|
|
|
2017-05-09 00:22:27 +02:00
|
|
|
/*should be merged into FileTile once FileTile is refactored to take a single id*/
|
2017-04-23 16:01:00 +02:00
|
|
|
class FileTile extends React.Component {
|
2017-05-09 00:22:27 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this._fileInfoSubscribeId = null
|
|
|
|
this._isMounted = null
|
|
|
|
this.state = {
|
|
|
|
showNsfwHelp: false,
|
|
|
|
isHidden: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this._isMounted = true;
|
|
|
|
if (this.props.hideOnRemove) {
|
|
|
|
this._fileInfoSubscribeId = lbry.fileInfoSubscribe(this.props.outpoint, this.onFileInfoUpdate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (this._fileInfoSubscribeId) {
|
|
|
|
lbry.fileInfoUnsubscribe(this.props.outpoint, this._fileInfoSubscribeId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onFileInfoUpdate(fileInfo) {
|
|
|
|
if (!fileInfo && this._isMounted && this.props.hideOnRemove) {
|
|
|
|
this.setState({
|
|
|
|
isHidden: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMouseOver() {
|
|
|
|
if (this.props.obscureNsfw && this.props.metadata && this.props.metadata.nsfw) {
|
|
|
|
this.setState({
|
|
|
|
showNsfwHelp: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMouseOut() {
|
|
|
|
if (this.state.showNsfwHelp) {
|
|
|
|
this.setState({
|
|
|
|
showNsfwHelp: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-23 16:01:00 +02:00
|
|
|
render() {
|
2017-05-09 00:22:27 +02:00
|
|
|
if (this.state.isHidden) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-04-23 16:01:00 +02:00
|
|
|
const {
|
2017-05-09 00:22:27 +02:00
|
|
|
metadata,
|
|
|
|
isResolvingUri,
|
|
|
|
navigate,
|
|
|
|
hidePrice,
|
2017-04-23 16:01:00 +02:00
|
|
|
} = this.props
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-05-09 00:22:27 +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;
|
|
|
|
|
|
|
|
let description = ""
|
|
|
|
if (isConfirmed) {
|
|
|
|
description = metadata.description
|
|
|
|
} else if (isResolvingUri) {
|
|
|
|
description = "Loading..."
|
|
|
|
} else {
|
|
|
|
description = <span className="empty">This file is pending confirmation</span>
|
2017-01-13 04:23:12 +01:00
|
|
|
}
|
|
|
|
|
2017-05-09 00:22:27 +02:00
|
|
|
return (
|
|
|
|
<section className={ 'file-tile card ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseOut.bind(this)}>
|
|
|
|
<Link onClick={() => navigate('/show', { uri })} className="card__link">
|
|
|
|
<div className="card__inner file-tile__row">
|
|
|
|
<div className="card__media"
|
|
|
|
style={{ backgroundImage: "url('" + (metadata && metadata.thumbnail ? metadata.thumbnail : lbry.imagePath('default-thumb.svg')) + "')" }}>
|
|
|
|
</div>
|
|
|
|
<div className="file-tile__content">
|
|
|
|
<div className="card__title-identity">
|
|
|
|
{ !hidePrice ? <span style={{float: "right"}}><FilePrice uri={uri} /></span> : null}
|
|
|
|
<h5 title={title}><TruncatedText lines={1}>{title}</TruncatedText></h5>
|
|
|
|
<div className="card__subtitle">
|
|
|
|
<UriIndicator uri={uri} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="card__content card__subtext">
|
|
|
|
<TruncatedText lines={3}>
|
|
|
|
{description}
|
|
|
|
</TruncatedText>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{this.state.showNsfwHelp && this.state.hovered
|
|
|
|
? <div className='card-overlay'>
|
|
|
|
<p>
|
|
|
|
This content is Not Safe For Work.
|
|
|
|
To view adult content, please change your <Link className="button-text" onClick={() => navigate('/settings')} label="Settings" />.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
: null}
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
</section>
|
|
|
|
);
|
2017-01-13 04:23:12 +01:00
|
|
|
}
|
2017-04-23 16:01:00 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 00:22:27 +02:00
|
|
|
export default FileTile
|