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

123 lines
3.9 KiB
React
Raw Normal View History

2018-01-04 06:05:20 +01:00
/* eslint-disable */
import React from 'react';
import lbry from 'lbry';
import lbryuri 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';
2018-01-04 06:05:20 +01:00
import Icon from 'component/common/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';
2018-01-04 06:05:20 +01:00
import Page from 'component/page';
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
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 = lbryuri.build({ channelName, claimId: channelClaimId }, false);
2017-12-08 21:14:35 +01:00
}
2017-05-12 19:14:06 +02:00
return (
2018-01-04 06:05:20 +01:00
<Page>
<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={lbryuri.normalize(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>
</div>
2017-09-17 22:33:52 +02:00
</div>
2018-01-04 06:05:20 +01:00
<SubscribeButton uri={subscriptionUri} channelName={channelName} />
<FileDetails uri={uri} />
2017-10-10 06:53:50 +02:00
</div>
2018-01-04 06:05:20 +01:00
)}
{tab === 'tip' && <WalletSendTip claim_id={claim.claim_id} uri={uri} />}
</div>
</section>
</Page>
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;
2018-01-04 06:05:20 +01:00
/* eslint-enable */