// @flow import * as MODALS from 'constants/modal_types'; import * as icons from 'constants/icons'; import * as React from 'react'; import { buildURI, normalizeURI } from 'lbry-redux'; import FileViewerInitiator from 'component/fileViewerInitiator'; import FilePrice from 'component/filePrice'; import FileDetails from 'component/fileDetails'; import FileActions from 'component/fileActions'; import DateTime from 'component/dateTime'; import Button from 'component/button'; import Page from 'component/page'; import FileDownloadLink from 'component/fileDownloadLink'; import RecommendedContent from 'component/recommendedContent'; import CommentsList from 'component/commentsList'; import CommentCreate from 'component/commentCreate'; import ClaimUri from 'component/claimUri'; import ClaimPreview from 'component/claimPreview'; import HelpLink from 'component/common/help-link'; import I18nMessage from 'component/i18nMessage/view'; export const FILE_WRAPPER_CLASS = 'grid-area--content'; type Props = { claim: StreamClaim, fileInfo: FileListItem, contentType: string, uri: string, claimIsMine: boolean, costInfo: ?{ cost: number }, fetchFileInfo: string => void, fetchCostInfo: string => void, setViewed: string => void, isSubscribed: ?string, isSubscribed: boolean, channelUri: string, viewCount: number, prepareEdit: ({}, string, {}) => void, openModal: (id: string, { uri: string, claimIsMine?: boolean, isSupport?: boolean }) => void, markSubscriptionRead: (string, string) => void, fetchViewCount: string => void, balance: number, title: string, nsfw: boolean, supportOption: boolean, }; class FilePage extends React.Component { componentDidMount() { const { uri, claim, fetchFileInfo, fetchCostInfo, setViewed, isSubscribed, fetchViewCount } = this.props; if (isSubscribed) { this.removeFromSubscriptionNotifications(); } fetchViewCount(claim.claim_id); // always refresh file info when entering file page to see if we have the file // @if TARGET='app' fetchFileInfo(uri); // @endif // See https://github.com/lbryio/lbry-desktop/pull/1563 for discussion fetchCostInfo(uri); setViewed(uri); } componentDidUpdate(prevProps: Props) { const { isSubscribed, claim, uri, fileInfo, setViewed, fetchViewCount, fetchFileInfo } = this.props; if (!prevProps.isSubscribed && isSubscribed) { this.removeFromSubscriptionNotifications(); } if (prevProps.uri !== uri) { fetchViewCount(claim.claim_id); } if (prevProps.uri !== uri) { setViewed(uri); } // @if TARGET='app' if (fileInfo === undefined) { fetchFileInfo(uri); } // @endif } removeFromSubscriptionNotifications() { // Always try to remove // If it doesn't exist, nothing will happen const { markSubscriptionRead, uri, channelUri } = this.props; markSubscriptionRead(channelUri, uri); } render() { const { claim, contentType, uri, openModal, claimIsMine, prepareEdit, costInfo, fileInfo, channelUri, viewCount, balance, title, nsfw, supportOption, } = this.props; // File info const { signing_channel: signingChannel } = claim; const channelName = signingChannel && signingChannel.name; const webShareable = costInfo && costInfo.cost === 0 && contentType && ['video', 'image', 'audio'].includes(contentType.split('/')[0]); // We want to use the short form uri for editing // This is what the user is used to seeing, they don't care about the claim id // We will select the claim id before they publish let editUri; if (claimIsMine) { const uriObject: { streamName: string, streamClaimId: string, channelName?: string } = { streamName: claim.name, streamClaimId: claim.claim_id, }; if (channelName) { uriObject.channelName = channelName; } editUri = buildURI(uriObject); } const insufficientCredits = !claimIsMine && costInfo && costInfo.cost > balance; return (
{!fileInfo && insufficientCredits && (
, }} > The publisher has chosen to charge LBC to view this content. Your balance is currently too low to view it. Check out %reward_link% for free LBC or send more LBC to your wallet.
)}
{nsfw && {__('Mature')}}

{title}

{viewCount} {viewCount !== 1 ? __('Views') : __('View')}
{claimIsMine && (
{/* @if TARGET='app' */} {/* @endif */}

{channelUri ? ( ) : (
{__('Anonymous')}
)}

{__('Comments')}
); } } export default FilePage;