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

138 lines
4.2 KiB
React
Raw Normal View History

import React from 'react';
import lbry from 'lbry';
import { buildURI, normalizeURI } from 'lbryURI';
import Video from 'component/video';
import { Thumbnail } from 'component/common';
import FilePrice from 'component/filePrice';
import FileDetails from 'component/fileDetails';
import UriIndicator from 'component/uriIndicator';
import Icon from 'component/icon';
import WalletSendTip from 'component/walletSendTip';
import DateTime from 'component/dateTime';
import * as icons from 'constants/icons';
import Link from 'component/link';
import SubscribeButton from 'component/subscribeButton';
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);
this.checkSubscription(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);
}
}
checkSubscription(props) {
2018-03-07 21:02:53 +01:00
if (
props.subscriptions
.map(subscription => subscription.channelName)
.indexOf(props.claim.channel_name) !== -1
) {
2018-03-15 09:35:47 +01:00
props.checkSubscription({
channelName: props.claim.channel_name,
uri: buildURI(
{
contentName: props.claim.channel_name,
claimId: props.claim.value.publisherSignature.certificateId,
},
false
),
});
2018-03-07 21:02:53 +01:00
}
}
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
const showTipBox = tab == 'tip';
2017-09-17 20:26:55 +02:00
2017-05-15 05:50:59 +02:00
if (!claim || !metadata) {
return <span className="empty">{__('Empty claim or metadata info.')}</span>;
2017-05-15 05:50:59 +02:00
}
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-12-08 21:38:20 +01:00
const { height, channel_name: channelName, value } = claim;
2017-12-08 21:14:35 +01:00
const channelClaimId =
value && value.publisherSignature && value.publisherSignature.certificateId;
2017-12-08 21:14:35 +01:00
let subscriptionUri;
2017-12-08 21:38:20 +01:00
if (channelName && channelClaimId) {
subscriptionUri = buildURI({ channelName, claimId: channelClaimId }, false);
2017-12-08 21:14:35 +01:00
}
2017-05-12 19:14:06 +02:00
return (
<section className={`card ${obscureNsfw ? 'card--obscured ' : ''}`}>
<div className="show-page-media">
{isPlayable ? (
<Video className="video-embedded" uri={uri} />
) : metadata && metadata.thumbnail ? (
<Thumbnail src={metadata.thumbnail} />
) : (
<Thumbnail />
)}
</div>
<div className="card__inner">
{(!tab || tab === 'details') && (
<div>
{' '}
<div className="card__title-identity">
{!fileInfo || fileInfo.written_bytes <= 0 ? (
<span style={{ float: 'right' }}>
<FilePrice uri={normalizeURI(uri)} />
{isRewardContent && (
<span>
{' '}
<Icon icon={icons.FEATURED} />
</span>
)}
</span>
) : null}
<h1>{title}</h1>
<div className="card__subtitle card--file-subtitle">
<UriIndicator uri={uri} link />
<span className="card__publish-date">
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>
<SubscribeButton uri={subscriptionUri} channelName={channelName} />
<FileDetails uri={uri} />
</div>
)}
{tab === 'tip' && <WalletSendTip claim_id={claim.claim_id} uri={uri} />}
</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;