2017-06-06 23:19:12 +02:00
|
|
|
import React from "react";
|
2017-09-12 06:24:04 +02:00
|
|
|
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";
|
2017-09-15 15:56:32 +02:00
|
|
|
import FileActions from "component/fileActions";
|
2017-06-06 23:19:12 +02:00
|
|
|
import Link from "component/link";
|
2017-06-26 16:00:24 +02:00
|
|
|
import { TruncatedText } from "component/common.js";
|
2017-06-06 23:19:12 +02:00
|
|
|
import FilePrice from "component/filePrice";
|
2017-06-26 16:00:24 +02:00
|
|
|
import NsfwOverlay from "component/nsfwOverlay";
|
2017-09-12 06:24:04 +02:00
|
|
|
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
|
|
|
|
2017-09-12 06:24:04 +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() {
|
2017-06-15 06:26:26 +02:00
|
|
|
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) {
|
2017-06-15 06:26:26 +02:00
|
|
|
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,
|
2017-09-15 15:56:32 +02:00
|
|
|
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,
|
2017-09-12 06:24:04 +02:00
|
|
|
showPrice,
|
|
|
|
showLocal,
|
2017-07-30 00:56:08 +02:00
|
|
|
rewardedContentClaimIds,
|
2017-09-12 06:24:04 +02:00
|
|
|
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-07-25 09:07:54 +02:00
|
|
|
|
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-01-13 04:23:12 +01:00
|
|
|
}
|
|
|
|
|
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-09-15 15:56:32 +02:00
|
|
|
<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">
|
2017-09-12 06:24:04 +02:00
|
|
|
<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>
|
2017-09-15 15:56:32 +02:00
|
|
|
{description &&
|
|
|
|
<div className="card__content card__subtext">
|
2017-10-05 05:07:04 +02:00
|
|
|
<TruncatedText lines={!showActions ? 4 : 2}>
|
2017-09-15 15:56:32 +02:00
|
|
|
{description}
|
|
|
|
</TruncatedText>
|
|
|
|
</div>}
|
2017-05-09 00:22:27 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-09-15 15:56:32 +02:00
|
|
|
</div>
|
2017-06-26 16:00:24 +02:00
|
|
|
{this.state.showNsfwHelp && <NsfwOverlay />}
|
2017-05-09 00:22:27 +02:00
|
|
|
</section>
|
|
|
|
);
|
2017-01-13 04:23:12 +01:00
|
|
|
}
|
2017-04-23 16:01:00 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default FileTile;
|