2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
2020-04-01 20:43:50 +02:00
|
|
|
import classnames from 'classnames';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Page from 'component/page';
|
2020-04-01 20:43:50 +02:00
|
|
|
import * as RENDER_MODES from 'constants/file_render_modes';
|
2020-04-01 22:13:22 +02:00
|
|
|
import ClaimUri from 'component/claimUri';
|
2020-04-01 20:43:50 +02:00
|
|
|
import FileTitle from 'component/fileTitle';
|
|
|
|
import FileRenderInitiator from 'component/fileRenderInitiator';
|
|
|
|
import FileRenderInline from 'component/fileRenderInline';
|
|
|
|
import FileRenderDownload from 'component/fileRenderDownload';
|
|
|
|
import Card from 'component/common/card';
|
|
|
|
import FileDetails from 'component/fileDetails';
|
2020-03-25 04:15:05 +01:00
|
|
|
import FileValues from 'component/fileValues';
|
|
|
|
import FileDescription from 'component/fileDescription';
|
2020-05-29 22:34:54 +02:00
|
|
|
import WaitUntilOnPage from 'component/common/wait-until-on-page';
|
2020-04-01 20:43:50 +02:00
|
|
|
import RecommendedContent from 'component/recommendedContent';
|
|
|
|
import CommentsList from 'component/commentsList';
|
|
|
|
import CommentCreate from 'component/commentCreate';
|
2020-07-16 03:59:52 +02:00
|
|
|
import YoutubeBadge from 'component/youtubeBadge';
|
2020-04-01 20:43:50 +02:00
|
|
|
|
2020-04-14 01:48:11 +02:00
|
|
|
export const FILE_WRAPPER_CLASS = 'file-page__video-container';
|
2019-08-13 07:35:13 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
2019-04-24 16:02:08 +02:00
|
|
|
claim: StreamClaim,
|
2020-04-01 20:43:50 +02:00
|
|
|
costInfo: ?{ includesData: boolean, cost: number },
|
2019-04-24 16:02:08 +02:00
|
|
|
fileInfo: FileListItem,
|
2018-03-26 23:32:43 +02:00
|
|
|
uri: string,
|
|
|
|
fetchFileInfo: string => void,
|
|
|
|
fetchCostInfo: string => void,
|
2018-10-10 07:22:06 +02:00
|
|
|
setViewed: string => void,
|
2018-10-19 22:38:07 +02:00
|
|
|
isSubscribed: boolean,
|
|
|
|
channelUri: string,
|
2020-04-01 20:43:50 +02:00
|
|
|
renderMode: string,
|
2018-10-19 22:38:07 +02:00
|
|
|
markSubscriptionRead: (string, string) => void,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class FilePage extends React.Component<Props> {
|
2017-05-13 00:50:51 +02:00
|
|
|
componentDidMount() {
|
2020-04-01 20:43:50 +02:00
|
|
|
const { uri, fetchFileInfo, fetchCostInfo, setViewed, isSubscribed } = this.props;
|
2018-10-19 22:38:07 +02:00
|
|
|
|
2019-05-02 20:29:45 +02:00
|
|
|
if (isSubscribed) {
|
2018-10-19 22:38:07 +02:00
|
|
|
this.removeFromSubscriptionNotifications();
|
|
|
|
}
|
2019-03-14 19:40:26 +01:00
|
|
|
|
2019-03-15 17:15:31 +01:00
|
|
|
// always refresh file info when entering file page to see if we have the file
|
2020-04-01 20:43:50 +02:00
|
|
|
// this could probably be refactored into more direct components now
|
2019-03-15 17:15:31 +01:00
|
|
|
// @if TARGET='app'
|
2019-02-12 18:26:50 +01:00
|
|
|
fetchFileInfo(uri);
|
2019-03-15 17:15:31 +01:00
|
|
|
// @endif
|
2017-05-12 19:14:06 +02:00
|
|
|
|
2018-07-12 20:39:12 +02:00
|
|
|
// See https://github.com/lbryio/lbry-desktop/pull/1563 for discussion
|
2018-06-07 19:47:09 +02:00
|
|
|
fetchCostInfo(uri);
|
2018-07-31 20:07:45 +02:00
|
|
|
setViewed(uri);
|
2017-05-12 19:14:06 +02:00
|
|
|
}
|
|
|
|
|
2018-10-19 22:38:07 +02:00
|
|
|
componentDidUpdate(prevProps: Props) {
|
2020-04-01 20:43:50 +02:00
|
|
|
const { isSubscribed, uri, fileInfo, setViewed, fetchFileInfo } = this.props;
|
2019-03-14 19:40:26 +01:00
|
|
|
|
2019-05-02 20:29:45 +02:00
|
|
|
if (!prevProps.isSubscribed && isSubscribed) {
|
2018-10-19 22:38:07 +02:00
|
|
|
this.removeFromSubscriptionNotifications();
|
|
|
|
}
|
2019-03-14 19:40:26 +01:00
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
if (prevProps.uri !== uri) {
|
|
|
|
setViewed(uri);
|
|
|
|
}
|
|
|
|
|
2019-05-29 21:35:46 +02:00
|
|
|
// @if TARGET='app'
|
2020-02-14 17:42:38 +01:00
|
|
|
if (prevProps.uri !== uri && fileInfo === undefined) {
|
2019-05-29 21:35:46 +02:00
|
|
|
fetchFileInfo(uri);
|
|
|
|
}
|
|
|
|
// @endif
|
2018-10-19 22:38:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
removeFromSubscriptionNotifications() {
|
|
|
|
// Always try to remove
|
|
|
|
// If it doesn't exist, nothing will happen
|
2019-05-02 20:29:45 +02:00
|
|
|
const { markSubscriptionRead, uri, channelUri } = this.props;
|
2018-10-19 22:38:07 +02:00
|
|
|
markSubscriptionRead(channelUri, uri);
|
|
|
|
}
|
2018-03-06 09:32:58 +01:00
|
|
|
|
2020-04-01 20:43:50 +02:00
|
|
|
renderFilePageLayout(uri: string, mode: string, cost: ?number) {
|
2020-07-13 14:57:03 +02:00
|
|
|
const { claim } = this.props;
|
|
|
|
const channelClaimId = claim.signing_channel ? claim.signing_channel.claim_id : null;
|
|
|
|
|
2020-04-01 20:43:50 +02:00
|
|
|
if (RENDER_MODES.FLOATING_MODES.includes(mode)) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-04-01 22:13:22 +02:00
|
|
|
<ClaimUri uri={uri} />
|
2020-07-16 03:59:52 +02:00
|
|
|
<YoutubeBadge channelClaimId={channelClaimId} includeSyncDate={false} />
|
2020-04-01 20:43:50 +02:00
|
|
|
<div className={FILE_WRAPPER_CLASS}>
|
|
|
|
<FileRenderInitiator uri={uri} />
|
|
|
|
</div>
|
|
|
|
{/* playables will be rendered and injected by <FileRenderFloating> */}
|
|
|
|
<FileTitle uri={uri} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RENDER_MODES.UNRENDERABLE_MODES.includes(mode)) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-04-01 22:13:22 +02:00
|
|
|
<ClaimUri uri={uri} />
|
2020-07-16 03:59:52 +02:00
|
|
|
<YoutubeBadge channelClaimId={channelClaimId} includeSyncDate={false} />
|
2020-04-01 20:43:50 +02:00
|
|
|
<FileTitle uri={uri} />
|
|
|
|
<FileRenderDownload uri={uri} isFree={cost === 0} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RENDER_MODES.TEXT_MODES.includes(mode)) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-04-01 22:13:22 +02:00
|
|
|
<ClaimUri uri={uri} />
|
2020-07-16 03:59:52 +02:00
|
|
|
<YoutubeBadge channelClaimId={channelClaimId} includeSyncDate={false} />
|
2020-04-01 20:43:50 +02:00
|
|
|
<FileTitle uri={uri} />
|
|
|
|
<FileRenderInitiator uri={uri} />
|
|
|
|
<FileRenderInline uri={uri} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-04-01 22:13:22 +02:00
|
|
|
<ClaimUri uri={uri} />
|
2020-07-16 03:59:52 +02:00
|
|
|
<YoutubeBadge channelClaimId={channelClaimId} includeSyncDate={false} />
|
2020-04-01 20:43:50 +02:00
|
|
|
<FileRenderInitiator uri={uri} />
|
|
|
|
<FileRenderInline uri={uri} />
|
|
|
|
<FileTitle uri={uri} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-12 19:14:06 +02:00
|
|
|
render() {
|
2020-04-01 20:43:50 +02:00
|
|
|
const { uri, renderMode, costInfo } = this.props;
|
2020-02-14 17:42:38 +01:00
|
|
|
|
2017-05-12 19:14:06 +02:00
|
|
|
return (
|
2020-04-01 20:43:50 +02:00
|
|
|
<Page className="file-page">
|
|
|
|
<div className={classnames('section card-stack', `file-page__${renderMode}`)}>
|
|
|
|
{this.renderFilePageLayout(uri, renderMode, costInfo ? costInfo.cost : null)}
|
|
|
|
</div>
|
|
|
|
<div className="section columns">
|
|
|
|
<div className="card-stack">
|
2020-03-25 04:15:05 +01:00
|
|
|
<FileDescription uri={uri} />
|
|
|
|
|
|
|
|
<FileValues uri={uri} />
|
|
|
|
|
2020-04-01 20:43:50 +02:00
|
|
|
<FileDetails uri={uri} />
|
2020-03-25 04:15:05 +01:00
|
|
|
|
2020-04-01 20:43:50 +02:00
|
|
|
<Card
|
|
|
|
title={__('Leave a Comment')}
|
|
|
|
actions={
|
|
|
|
<div>
|
|
|
|
<CommentCreate uri={uri} />
|
2020-05-29 22:34:54 +02:00
|
|
|
<WaitUntilOnPage>
|
|
|
|
<CommentsList uri={uri} />
|
|
|
|
</WaitUntilOnPage>
|
2020-04-01 20:43:50 +02:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
2019-06-17 22:32:38 +02:00
|
|
|
</div>
|
2020-05-29 22:34:54 +02:00
|
|
|
<WaitUntilOnPage>
|
|
|
|
<RecommendedContent uri={uri} />
|
|
|
|
</WaitUntilOnPage>
|
2020-04-01 20:43:50 +02:00
|
|
|
</div>
|
2018-03-26 23:32:43 +02:00
|
|
|
</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
|
|
|
|
2017-05-26 02:16:25 +02:00
|
|
|
export default FilePage;
|