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

150 lines
4.2 KiB
React
Raw Normal View History

2017-06-06 17:19:12 -04:00
import React from "react";
import * as icons from "constants/icons";
2017-06-06 17:19:12 -04:00
import lbryuri from "lbryuri.js";
2017-07-14 00:18:28 +01:00
import CardMedia from "component/cardMedia";
import FileActions from "component/fileActions";
2017-06-06 17:19:12 -04:00
import Link from "component/link";
import { TruncatedText } from "component/common.js";
2017-06-06 17:19:12 -04:00
import FilePrice from "component/filePrice";
import NsfwOverlay from "component/nsfwOverlay";
import Icon from "component/icon";
2017-04-23 21:01:00 +07:00
2017-06-07 21:42:19 -07:00
class FileTile extends React.PureComponent {
2017-06-06 17:19:12 -04:00
static SHOW_EMPTY_PUBLISH = "publish";
static SHOW_EMPTY_PENDING = "pending";
2017-05-09 21:33:13 -04:00
static defaultProps = {
showPrice: true,
showLocal: true,
};
2017-05-08 18:22:27 -04:00
constructor(props) {
2017-06-06 17:19:12 -04:00
super(props);
2017-05-08 18:22:27 -04:00
this.state = {
showNsfwHelp: false,
2017-06-06 17:19:12 -04:00
};
2017-05-08 18:22:27 -04:00
}
componentDidMount() {
const { isResolvingUri, claim, uri, resolveUri } = this.props;
if (!isResolvingUri && !claim && uri) resolveUri(uri);
2017-06-05 15:48:06 +07:00
}
2017-05-11 19:28:43 -04:00
2017-06-05 15:48:06 +07:00
componentWillReceiveProps(nextProps) {
const { isResolvingUri, claim, uri, resolveUri } = this.props;
2017-06-05 15:48:06 +07:00
if (!isResolvingUri && claim === undefined && uri) resolveUri(uri);
2017-05-08 18:22:27 -04:00
}
handleMouseOver() {
2017-06-06 17:19:12 -04:00
if (
this.props.obscureNsfw &&
this.props.metadata &&
this.props.metadata.nsfw
) {
2017-05-08 18:22:27 -04:00
this.setState({
showNsfwHelp: true,
});
}
}
handleMouseOut() {
if (this.state.showNsfwHelp) {
this.setState({
showNsfwHelp: false,
});
}
}
2017-04-23 21:01:00 +07:00
render() {
const {
2017-05-09 21:33:13 -04:00
claim,
showActions,
2017-05-08 18:22:27 -04:00
metadata,
isResolvingUri,
2017-05-09 21:33:13 -04:00
showEmpty,
2017-05-08 18:22:27 -04:00
navigate,
showPrice,
showLocal,
2017-07-29 18:56:08 -04:00
rewardedContentClaimIds,
fileInfo,
2017-06-06 17:19:12 -04:00
} = this.props;
2017-04-28 22:14:44 +07:00
2017-05-08 18:22:27 -04:00
const uri = lbryuri.normalize(this.props.uri);
2017-05-09 21:33:13 -04:00
const isClaimed = !!claim;
2017-06-06 17:19:12 -04:00
const isClaimable = lbryuri.isClaimable(uri);
const title = isClaimed && metadata && metadata.title
? metadata.title
2017-07-08 15:03:12 +07:00
: lbryuri.parse(uri).contentName;
2017-07-14 00:18:28 +01:00
const thumbnail = metadata && metadata.thumbnail
? metadata.thumbnail
: null;
2017-05-09 21:33:13 -04:00
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
2017-08-08 10:36:14 +01:00
const isRewardContent =
claim && rewardedContentClaimIds.includes(claim.claim_id);
2017-06-06 17:19:12 -04:00
let onClick = () => navigate("/show", { uri });
2017-05-08 18:22:27 -04:00
2017-06-06 17:19:12 -04:00
let description = "";
2017-05-09 21:33:13 -04:00
if (isClaimed) {
2017-06-06 17:19:12 -04:00
description = metadata && metadata.description;
2017-05-08 18:22:27 -04:00
} else if (isResolvingUri) {
2017-06-06 17:19:12 -04:00
description = __("Loading...");
2017-05-09 21:33:13 -04:00
} else if (showEmpty === FileTile.SHOW_EMPTY_PUBLISH) {
2017-06-06 17:19:12 -04:00
onClick = () => navigate("/publish", {});
description = (
<span className="empty">
{__("This location is unused.")} {" "}
{isClaimable &&
<span className="button-text">{__("Put something here!")}</span>}
</span>
);
2017-05-09 21:33:13 -04:00
} else if (showEmpty === FileTile.SHOW_EMPTY_PENDING) {
2017-06-06 17:19:12 -04:00
description = (
<span className="empty">
{__("This file is pending confirmation.")}
</span>
);
}
2017-05-08 18:22:27 -04:00
return (
2017-06-06 17:19:12 -04: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 16:12:48 -04:00
<div className={"card__inner file-tile__row"}>
2017-07-14 00:18:28 +01:00
<CardMedia title={title} thumbnail={thumbnail} />
2017-05-08 18:22:27 -04:00
<div className="file-tile__content">
2017-05-09 16:12:48 -04: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-05-09 16:12:48 -04:00
<div className="meta">{uri}</div>
2017-07-29 18:56:08 -04:00
<h3>
<TruncatedText lines={1}>{title}</TruncatedText>
</h3>
2017-05-08 18:22:27 -04:00
</div>
{description &&
<div className="card__content card__subtext">
<TruncatedText lines={!showActions ? 4 : 2}>
{description}
</TruncatedText>
</div>}
2017-05-08 18:22:27 -04:00
</div>
</div>
</div>
{this.state.showNsfwHelp && <NsfwOverlay />}
2017-05-08 18:22:27 -04:00
</section>
);
}
2017-04-23 21:01:00 +07:00
}
2017-06-05 21:21:55 -07:00
export default FileTile;