lbry-desktop/ui/js/component/fileTile/view.jsx

128 lines
3.9 KiB
React
Raw Normal View History

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
class FileTile extends React.Component {
2017-05-10 03:33:13 +02:00
static SHOW_EMPTY_PUBLISH = "publish"
static SHOW_EMPTY_PENDING = "pending"
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-10 03:33:13 +02:00
claim,
2017-05-09 00:22:27 +02:00
metadata,
isResolvingUri,
2017-05-10 03:33:13 +02:00
showEmpty,
2017-05-09 00:22:27 +02:00
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);
2017-05-10 03:33:13 +02:00
const isClaimed = !!claim;
const title = isClaimed && metadata && metadata.title ? metadata.title : uri;
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
let onClick = () => navigate('/show', { uri })
2017-05-09 00:22:27 +02:00
let description = ""
2017-05-10 03:33:13 +02:00
if (isClaimed) {
2017-05-09 00:22:27 +02:00
description = metadata.description
} else if (isResolvingUri) {
description = "Loading..."
2017-05-10 03:33:13 +02:00
} else if (showEmpty === FileTile.SHOW_EMPTY_PUBLISH) {
onClick = () => navigate('/publish')
description = <span className="empty">This location is unclaimed - <Link label="put something here" />!</span>
} else if (showEmpty === FileTile.SHOW_EMPTY_PENDING) {
2017-05-09 22:12:48 +02:00
description = <span className="empty">This file is pending confirmation.</span>
}
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)}>
2017-05-10 03:33:13 +02:00
<Link onClick={onClick} className="card__link" className="card__link">
2017-05-09 22:12:48 +02:00
<div className={"card__inner file-tile__row"}>
2017-05-09 00:22:27 +02:00
<div className="card__media"
style={{ backgroundImage: "url('" + (metadata && metadata.thumbnail ? metadata.thumbnail : lbry.imagePath('default-thumb.svg')) + "')" }}>
</div>
<div className="file-tile__content">
2017-05-09 22:12:48 +02:00
<div className="card__title-primary">
2017-05-10 03:33:13 +02:00
{ !hidePrice ? <FilePrice uri={this.props.uri} /> : null}
2017-05-09 22:12:48 +02:00
<div className="meta">{uri}</div>
<h3><TruncatedText lines={1}>{title}</TruncatedText></h3>
2017-05-09 00:22:27 +02:00
</div>
<div className="card__content card__subtext">
<TruncatedText lines={3}>
2017-05-10 03:33:13 +02:00
{description}
2017-05-09 00:22:27 +02:00
</TruncatedText>
</div>
</div>
</div>
</Link>
2017-05-09 22:12:48 +02:00
{this.state.showNsfwHelp
? <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}
2017-05-09 00:22:27 +02:00
</section>
);
}
2017-04-23 16:01:00 +02:00
}
2017-05-09 00:22:27 +02:00
export default FileTile