lbry-desktop/src/renderer/page/file/view.jsx

114 lines
3.3 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 Video from "component/video";
import { Thumbnail } from "component/common";
import FilePrice from "component/filePrice";
2017-09-17 22:33:52 +02:00
import FileDetails from "component/fileDetails";
2017-06-06 23:19:12 +02:00
import UriIndicator from "component/uriIndicator";
import Icon from "component/icon";
2017-09-17 22:33:52 +02:00
import WalletSendTip from "component/walletSendTip";
import DateTime from "component/dateTime";
import * as icons from "constants/icons";
2017-06-08 06:42:19 +02:00
class FilePage extends React.PureComponent {
2017-05-13 00:50:51 +02:00
componentDidMount() {
2017-06-06 23:19:12 +02:00
this.fetchFileInfo(this.props);
this.fetchCostInfo(this.props);
2017-05-12 19:14:06 +02:00
}
componentWillReceiveProps(nextProps) {
2017-06-06 23:19:12 +02:00
this.fetchFileInfo(nextProps);
2017-05-12 19:14:06 +02:00
}
fetchFileInfo(props) {
2017-05-13 00:50:51 +02:00
if (props.fileInfo === undefined) {
2017-06-06 23:19:12 +02:00
props.fetchFileInfo(props.uri);
2017-05-12 19:14:06 +02:00
}
}
fetchCostInfo(props) {
if (props.costInfo === undefined) {
2017-06-06 23:19:12 +02:00
props.fetchCostInfo(props.uri);
}
}
2017-05-12 19:14:06 +02:00
render() {
const {
claim,
fileInfo,
metadata,
contentType,
2017-09-17 20:26:55 +02:00
tab,
uri,
2017-07-30 00:56:08 +02:00
rewardedContentClaimIds,
} = this.props;
2017-05-01 22:50:07 +02:00
2017-09-17 20:26:55 +02:00
const showTipBox = tab == "tip";
2017-05-15 05:50:59 +02:00
if (!claim || !metadata) {
2017-06-06 23:19:12 +02:00
return (
<span className="empty">{__("Empty claim or metadata info.")}</span>
);
2017-05-15 05:50:59 +02:00
}
2017-10-08 22:23:55 +02:00
const { height } = claim;
2017-06-06 23:19:12 +02:00
const title = metadata.title;
2017-07-30 00:56:08 +02:00
const isRewardContent = rewardedContentClaimIds.includes(claim.claim_id);
2017-06-06 23:19:12 +02:00
const mediaType = lbry.getMediaType(contentType);
const player = require("render-media");
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
2017-06-06 23:19:12 +02:00
const isPlayable =
Object.values(player.mime).indexOf(contentType) !== -1 ||
mediaType === "audio";
2017-05-01 22:50:07 +02:00
2017-05-12 19:14:06 +02:00
return (
2017-10-10 06:53:50 +02:00
<section className={"card " + (obscureNsfw ? "card--obscured " : "")}>
<div className="show-page-media">
2017-11-22 21:28:56 +01:00
{isPlayable ? (
<Video className="video-embedded" uri={uri} />
) : metadata && metadata.thumbnail ? (
<Thumbnail src={metadata.thumbnail} />
) : (
<Thumbnail />
)}
2017-10-10 06:53:50 +02:00
</div>
<div className="card__inner">
2017-11-22 21:28:56 +01:00
{(!tab || tab === "details") && (
2017-10-10 06:53:50 +02:00
<div>
2017-11-22 21:28:56 +01:00
{" "}
2017-10-10 06:53:50 +02:00
<div className="card__title-identity">
2017-11-22 21:28:56 +01:00
{!fileInfo || fileInfo.written_bytes <= 0 ? (
<span style={{ float: "right" }}>
<FilePrice uri={lbryuri.normalize(uri)} />
{isRewardContent && (
<span>
{" "}
<Icon icon={icons.FEATURED} />
</span>
)}
</span>
) : null}
2017-10-10 06:53:50 +02:00
<h1>{title}</h1>
2017-11-22 21:28:56 +01:00
<div className="card__subtitle card--file-subtitle">
2017-10-10 06:53:50 +02:00
<UriIndicator uri={uri} link={true} />
2017-11-22 21:28:56 +01:00
<span className="card__publish-date">
2017-10-10 06:53:50 +02:00
Published on{" "}
<DateTime block={height} show={DateTime.SHOW_DATE} />
</span>
2017-09-17 22:33:52 +02:00
</div>
2017-10-10 06:53:50 +02:00
</div>
<FileDetails uri={uri} />
2017-11-22 21:28:56 +01:00
</div>
)}
{tab === "tip" && (
<WalletSendTip claim_id={claim.claim_id} uri={uri} />
)}
2017-10-10 06:53:50 +02:00
</div>
</section>
2017-06-06 23:19:12 +02:00
);
2017-05-12 19:14:06 +02:00
}
2017-05-05 07:10:37 +02:00
}
2017-05-01 21:59:40 +02:00
export default FilePage;