// @flow import * as React from 'react'; import classnames from 'classnames'; import { useIsMediumScreen } from 'effects/use-screensize'; import Page from 'component/page'; import * as RENDER_MODES from 'constants/file_render_modes'; import FileTitleSection from 'component/fileTitleSection'; import FileRenderInitiator from 'component/fileRenderInitiator'; import FileRenderInline from 'component/fileRenderInline'; import FileRenderDownload from 'component/fileRenderDownload'; import RecommendedContent from 'component/recommendedContent'; import CollectionContent from 'component/collectionContentSidebar'; import CommentsList from 'component/commentsList'; import Empty from 'component/common/empty'; import PostViewer from 'component/postViewer'; export const PRIMARY_PLAYER_WRAPPER_CLASS = 'file-page__video-container'; type Props = { costInfo: ?{ includesData: boolean, cost: number }, fileInfo: FileListItem, uri: string, fetchFileInfo: (string) => void, fetchCostInfo: (string) => void, setViewed: (string) => void, renderMode: string, obscureNsfw: boolean, isMature: boolean, linkedCommentId?: string, setPrimaryUri: (?string) => void, collection?: Collection, collectionId: string, videoTheaterMode: boolean, claimIsMine: boolean, commentsDisabled: boolean, clearPosition: (string) => void, position: number, }; function FilePage(props: Props) { const { uri, renderMode, fetchFileInfo, fetchCostInfo, setViewed, fileInfo, obscureNsfw, isMature, costInfo, linkedCommentId, setPrimaryUri, videoTheaterMode, commentsDisabled, collection, collectionId, clearPosition, position, } = props; const cost = costInfo ? costInfo.cost : null; const hasFileInfo = fileInfo !== undefined; const isMediumScreen = useIsMediumScreen(); const isMarkdown = renderMode === RENDER_MODES.MARKDOWN; const videoPlayedEnoughToResetPosition = React.useMemo(() => { const durationInSecs = fileInfo && fileInfo.metadata && fileInfo.metadata.video ? fileInfo.metadata.video.duration : 0; const isVideoTooShort = durationInSecs <= 10; const almostFinishedPlaying = position / durationInSecs >= 0.9; return isVideoTooShort || almostFinishedPlaying; }, [fileInfo, position]); React.useEffect(() => { // always refresh file info when entering file page to see if we have the file // this could probably be refactored into more direct components now // @if TARGET='app' if (!hasFileInfo) { fetchFileInfo(uri); } // @endif if (collectionId) { clearPosition(uri); } if (fileInfo && videoPlayedEnoughToResetPosition) { clearPosition(uri); } // See https://github.com/lbryio/lbry-desktop/pull/1563 for discussion fetchCostInfo(uri); setViewed(uri); setPrimaryUri(uri); return () => { setPrimaryUri(null); }; }, [ uri, hasFileInfo, fileInfo, videoPlayedEnoughToResetPosition, fetchFileInfo, collectionId, clearPosition, fetchCostInfo, setViewed, setPrimaryUri, ]); function renderFilePageLayout() { if (RENDER_MODES.FLOATING_MODES.includes(renderMode)) { return (
{/* playables will be rendered and injected by */}
); } if (RENDER_MODES.UNRENDERABLE_MODES.includes(renderMode)) { return ( ); } if (isMarkdown) { return ; } if (RENDER_MODES.TEXT_MODES.includes(renderMode)) { return ( ); } if (renderMode === RENDER_MODES.IMAGE) { return (
); } return ( ); } if (obscureNsfw && isMature) { return (
{collection && !isMarkdown && !videoTheaterMode && !isMediumScreen && ( )} {!collection && !isMarkdown && !videoTheaterMode && !isMediumScreen && }
); } return (
{renderFilePageLayout()} {!isMarkdown && (
{RENDER_MODES.FLOATING_MODES.includes(renderMode) && } {commentsDisabled && } {!commentsDisabled && }
{!collection && !isMarkdown && videoTheaterMode && !isMediumScreen && } {collection && !isMarkdown && videoTheaterMode && !isMediumScreen && ( )}
)}
{collection && !isMarkdown && !videoTheaterMode && !isMediumScreen && ( )} {!collection && !isMarkdown && !videoTheaterMode && !isMediumScreen && } {isMarkdown && (
{!commentsDisabled && }
)}
); } export default FilePage;