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';
|
|
|
|
import FileTitle from 'component/fileTitle';
|
|
|
|
import FileRenderInitiator from 'component/fileRenderInitiator';
|
|
|
|
import FileRenderInline from 'component/fileRenderInline';
|
|
|
|
import FileRenderDownload from 'component/fileRenderDownload';
|
|
|
|
import RecommendedContent from 'component/recommendedContent';
|
|
|
|
import CommentsList from 'component/commentsList';
|
2021-02-04 06:45:49 +01:00
|
|
|
import Empty from 'component/common/empty';
|
2020-04-01 20:43:50 +02:00
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
export const PRIMARY_PLAYER_WRAPPER_CLASS = 'file-page__video-container';
|
2019-08-13 07:35:13 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
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,
|
2020-04-01 20:43:50 +02:00
|
|
|
renderMode: string,
|
2020-07-21 09:26:56 +02:00
|
|
|
obscureNsfw: boolean,
|
|
|
|
isMature: boolean,
|
2020-08-24 19:35:21 +02:00
|
|
|
linkedComment: any,
|
2020-10-20 19:10:02 +02:00
|
|
|
setPrimaryUri: (?string) => void,
|
2021-01-08 16:21:27 +01:00
|
|
|
videoTheaterMode: boolean,
|
2021-02-05 00:00:07 +01:00
|
|
|
commentsDisabled: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
function FilePage(props: Props) {
|
|
|
|
const {
|
|
|
|
uri,
|
|
|
|
renderMode,
|
|
|
|
fetchFileInfo,
|
|
|
|
fetchCostInfo,
|
|
|
|
setViewed,
|
|
|
|
fileInfo,
|
|
|
|
obscureNsfw,
|
|
|
|
isMature,
|
|
|
|
costInfo,
|
|
|
|
linkedComment,
|
|
|
|
setPrimaryUri,
|
2021-01-08 16:21:27 +01:00
|
|
|
videoTheaterMode,
|
2021-02-05 00:00:07 +01:00
|
|
|
commentsDisabled,
|
2020-10-20 19:10:02 +02:00
|
|
|
} = props;
|
|
|
|
const cost = costInfo ? costInfo.cost : null;
|
|
|
|
const hasFileInfo = fileInfo !== undefined;
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
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'
|
2020-10-20 19:10:02 +02:00
|
|
|
if (!hasFileInfo) {
|
|
|
|
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);
|
2020-10-20 19:10:02 +02:00
|
|
|
setPrimaryUri(uri);
|
2019-03-14 19:40:26 +01:00
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
return () => {
|
|
|
|
setPrimaryUri(null);
|
|
|
|
};
|
|
|
|
}, [uri, hasFileInfo, fetchFileInfo, fetchCostInfo, setViewed, setPrimaryUri]);
|
2018-10-19 22:38:07 +02:00
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
function renderFilePageLayout() {
|
|
|
|
if (RENDER_MODES.FLOATING_MODES.includes(renderMode)) {
|
2020-04-01 20:43:50 +02:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-10-20 19:10:02 +02:00
|
|
|
<div className={PRIMARY_PLAYER_WRAPPER_CLASS}>
|
2021-01-08 16:21:27 +01:00
|
|
|
<FileRenderInitiator uri={uri} videoTheaterMode={videoTheaterMode} />
|
2020-04-01 20:43:50 +02:00
|
|
|
</div>
|
|
|
|
{/* playables will be rendered and injected by <FileRenderFloating> */}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
if (RENDER_MODES.UNRENDERABLE_MODES.includes(renderMode)) {
|
2020-04-01 20:43:50 +02:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<FileTitle uri={uri} />
|
|
|
|
<FileRenderDownload uri={uri} isFree={cost === 0} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
if (RENDER_MODES.TEXT_MODES.includes(renderMode)) {
|
2020-04-01 20:43:50 +02:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<FileTitle uri={uri} />
|
|
|
|
<FileRenderInitiator uri={uri} />
|
|
|
|
<FileRenderInline uri={uri} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2021-01-08 16:21:27 +01:00
|
|
|
<FileRenderInitiator uri={uri} videoTheaterMode={videoTheaterMode} />
|
2020-04-01 20:43:50 +02:00
|
|
|
<FileRenderInline uri={uri} />
|
|
|
|
<FileTitle uri={uri} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-08 16:21:27 +01:00
|
|
|
if (obscureNsfw && isMature) {
|
2020-07-21 09:26:56 +02:00
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
<FileTitle uri={uri} isNsfwBlocked />
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-20 19:10:02 +02:00
|
|
|
return (
|
|
|
|
<Page className="file-page" filePage>
|
|
|
|
<div className={classnames('section card-stack', `file-page__${renderMode}`)}>
|
|
|
|
{renderFilePageLayout()}
|
2020-09-11 19:51:31 +02:00
|
|
|
|
2021-01-08 16:21:27 +01:00
|
|
|
<div className="file-page__secondary-content">
|
|
|
|
<div>
|
|
|
|
{RENDER_MODES.FLOATING_MODES.includes(renderMode) && <FileTitle uri={uri} />}
|
2021-02-05 00:00:07 +01:00
|
|
|
{commentsDisabled && <Empty text={__('The creator of this content has disabled comments.')} />}
|
|
|
|
{!commentsDisabled && <CommentsList uri={uri} linkedComment={linkedComment} />}
|
2021-01-08 16:21:27 +01:00
|
|
|
</div>
|
|
|
|
{videoTheaterMode && <RecommendedContent uri={uri} />}
|
|
|
|
</div>
|
2020-10-20 19:10:02 +02:00
|
|
|
</div>
|
2020-08-10 22:47:39 +02:00
|
|
|
|
2021-01-08 16:21:27 +01:00
|
|
|
{!videoTheaterMode && <RecommendedContent uri={uri} />}
|
2020-10-20 19:10:02 +02:00
|
|
|
</Page>
|
|
|
|
);
|
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;
|