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

150 lines
4.2 KiB
React
Raw Normal View History

2017-06-06 23:19:12 +02:00
import React from "react";
import * as icons from "constants/icons";
2017-06-06 23:19:12 +02:00
import lbryuri from "lbryuri.js";
2017-07-14 01:18:28 +02:00
import CardMedia from "component/cardMedia";
import FileActions from "component/fileActions";
2017-06-06 23:19:12 +02:00
import Link from "component/link";
import { TruncatedText } from "component/common.js";
2017-06-06 23:19:12 +02:00
import FilePrice from "component/filePrice";
import NsfwOverlay from "component/nsfwOverlay";
import Icon from "component/icon";
2017-04-23 16:01:00 +02:00
2017-06-08 06:42:19 +02:00
class FileTile extends React.PureComponent {
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
static defaultProps = {
showPrice: true,
showLocal: true,
};
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() {
const { isResolvingUri, claim, uri, resolveUri } = this.props;
if (!isResolvingUri && !claim && uri) resolveUri(uri);
2017-06-05 10:48:06 +02:00
}
2017-05-12 01:28:43 +02:00
2017-06-05 10:48:06 +02:00
componentWillReceiveProps(nextProps) {
const { isResolvingUri, claim, uri, resolveUri } = this.props;
2017-06-05 10:48:06 +02:00
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,
showActions,
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,
showPrice,
showLocal,
2017-07-30 00:56:08 +02:00
rewardedContentClaimIds,
fileInfo,
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
2017-07-08 10:03:12 +02:00
: lbryuri.parse(uri).contentName;
2017-07-14 01:18:28 +02:00
const thumbnail = metadata && metadata.thumbnail
? metadata.thumbnail
: null;
2017-05-10 03:33:13 +02:00
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
2017-08-08 11:36:14 +02:00
const isRewardContent =
claim && rewardedContentClaimIds.includes(claim.claim_id);
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)}
>
<div onClick={onClick} className="card__link">
2017-05-09 22:12:48 +02:00
<div className={"card__inner file-tile__row"}>
2017-07-14 01:18:28 +02:00
<CardMedia title={title} thumbnail={thumbnail} />
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">
<span className="card__indicators">
{showPrice && <FilePrice uri={this.props.uri} />}
{" "}
{isRewardContent && <Icon icon={icons.FEATURED} />}
{" "}
{showLocal && fileInfo && <Icon icon={icons.LOCAL} />}
</span>
2017-07-30 00:56:08 +02:00
<h3>
<TruncatedText lines={1}>{title}</TruncatedText>
</h3>
2017-10-05 05:07:04 +02:00
<span className="file-tile__uri">{uri}</span>
2017-05-09 00:22:27 +02:00
</div>
{description &&
<div className="card__content card__subtext">
2017-10-05 06:13:06 +02:00
<TruncatedText lines={!showActions ? 3 : 2}>
{description}
</TruncatedText>
</div>}
2017-05-09 00:22:27 +02:00
</div>
</div>
</div>
{this.state.showNsfwHelp && <NsfwOverlay />}
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;