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

148 lines
4.1 KiB
React
Raw Normal View History

2017-06-06 23:19:12 +02:00
import React from "react";
import lbry from "lbry.js";
import lbryuri from "lbryuri.js";
import Link from "component/link";
import FileActions from "component/fileActions";
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-06-06 23:19:12 +02:00
static SHOW_EMPTY_PUBLISH = "publish";
static SHOW_EMPTY_PENDING = "pending";
2017-05-10 03:33:13 +02:00
2017-05-09 00:22:27 +02:00
constructor(props) {
2017-06-06 23:19:12 +02:00
super(props);
2017-05-09 00:22:27 +02:00
this.state = {
showNsfwHelp: false,
2017-06-06 23:19:12 +02:00
};
2017-05-09 00:22:27 +02:00
}
componentDidMount() {
2017-06-05 10:48:06 +02:00
this.resolve(this.props);
}
2017-05-12 01:28:43 +02:00
2017-06-05 10:48:06 +02:00
componentWillReceiveProps(nextProps) {
this.resolve(nextProps);
}
resolve({ isResolvingUri, claim, uri, resolveUri }) {
if (!isResolvingUri && claim === undefined && uri) resolveUri(uri);
2017-05-09 00:22:27 +02:00
}
handleMouseOver() {
2017-06-06 23:19:12 +02:00
if (
this.props.obscureNsfw &&
this.props.metadata &&
this.props.metadata.nsfw
) {
2017-05-09 00:22:27 +02:00
this.setState({
showNsfwHelp: true,
});
}
}
handleMouseOut() {
if (this.state.showNsfwHelp) {
this.setState({
showNsfwHelp: false,
});
}
}
2017-04-23 16:01:00 +02:00
render() {
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-06-06 23:19:12 +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;
2017-06-06 23:19:12 +02:00
const isClaimable = lbryuri.isClaimable(uri);
const title = isClaimed && metadata && metadata.title
? metadata.title
: uri;
2017-05-10 03:33:13 +02:00
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
2017-06-06 23:19:12 +02:00
let onClick = () => navigate("/show", { uri });
2017-05-09 00:22:27 +02:00
2017-06-06 23:19:12 +02:00
let description = "";
2017-05-10 03:33:13 +02:00
if (isClaimed) {
2017-06-06 23:19:12 +02:00
description = metadata && metadata.description;
2017-05-09 00:22:27 +02:00
} else if (isResolvingUri) {
2017-06-06 23:19:12 +02:00
description = __("Loading...");
2017-05-10 03:33:13 +02:00
} else if (showEmpty === FileTile.SHOW_EMPTY_PUBLISH) {
2017-06-06 23:19:12 +02:00
onClick = () => navigate("/publish", {});
description = (
<span className="empty">
{__("This location is unused.")} {" "}
{isClaimable &&
<span className="button-text">{__("Put something here!")}</span>}
</span>
);
2017-05-10 03:33:13 +02:00
} else if (showEmpty === FileTile.SHOW_EMPTY_PENDING) {
2017-06-06 23:19:12 +02:00
description = (
<span className="empty">
{__("This file is pending confirmation.")}
</span>
);
}
2017-05-09 00:22:27 +02:00
return (
2017-06-06 23:19:12 +02:00
<section
className={"file-tile card " + (obscureNsfw ? "card--obscured " : "")}
onMouseEnter={this.handleMouseOver.bind(this)}
onMouseLeave={this.handleMouseOut.bind(this)}
>
2017-05-12 01:28:43 +02:00
<Link onClick={onClick} className="card__link">
2017-05-09 22:12:48 +02:00
<div className={"card__inner file-tile__row"}>
2017-06-06 23:19:12 +02:00
<div
className="card__media"
style={{
backgroundImage:
"url('" +
(metadata && metadata.thumbnail
? metadata.thumbnail
: lbry.imagePath("default-thumb.svg")) +
"')",
}}
/>
2017-05-09 00:22:27 +02:00
<div className="file-tile__content">
2017-05-09 22:12:48 +02:00
<div className="card__title-primary">
2017-06-06 23:19:12 +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
2017-06-06 23:19:12 +02:00
? <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>
2017-05-09 22:12:48 +02:00
: null}
2017-05-09 00:22:27 +02:00
</section>
);
}
2017-04-23 16:01:00 +02:00
}
2017-06-06 06:21:55 +02:00
export default FileTile;