// @flow import * as ICONS from 'constants/icons'; import React, { useEffect } from 'react'; import Button from 'component/button'; import classnames from 'classnames'; import LoadingScreen from 'component/common/loading-screen'; import FileRender from 'component/fileRender'; import UriIndicator from 'component/uriIndicator'; import usePersistedState from 'util/use-persisted-state'; import { FILE_WRAPPER_CLASS } from 'page/file/view'; import Draggable from 'react-draggable'; import Tooltip from 'component/common/tooltip'; type Props = { mediaType: string, isLoading: boolean, isPlaying: boolean, fileInfo: FileListItem, uri: string, obscurePreview: boolean, insufficientCredits: boolean, isStreamable: boolean, thumbnail?: string, streamingUrl?: string, floatingPlayer: boolean, pageUri: ?string, title: ?string, floatingPlayerEnabled: boolean, clearPlayingUri: () => void, }; export default function FileViewer(props: Props) { const { isPlaying, fileInfo, uri, streamingUrl, isStreamable, pageUri, title, clearPlayingUri, floatingPlayerEnabled, } = props; const [fileViewerRect, setFileViewerRect] = usePersistedState('inline-file-viewer:rect'); const [position, setPosition] = usePersistedState('floating-file-viewer:position', { x: -25, y: window.innerHeight - 400, }); const inline = pageUri === uri; const isReadyToPlay = (IS_WEB && isStreamable) || (isStreamable && streamingUrl) || (fileInfo && fileInfo.completed); const loadingMessage = !isStreamable && fileInfo && fileInfo.blobs_completed >= 1 && (!fileInfo.download_path || !fileInfo.written_bytes) ? __("It looks like you deleted or moved this file. We're rebuilding it now. It will only take a few seconds.") : __('Loading'); function handleDrag(e, ui) { const { x, y } = position; const newX = x + ui.deltaX; const newY = y + ui.deltaY; setPosition({ x: newX, y: newY, }); } useEffect(() => { function handleResize() { const element = document.querySelector(`.${FILE_WRAPPER_CLASS}`); if (!element) { throw new Error("Can't find file viewer wrapper to attach to"); } const rect = element.getBoundingClientRect(); // @FlowFixMe setFileViewerRect(rect); } if (inline) { handleResize(); window.addEventListener('resize', handleResize); return () => { window.removeEventListener('resize', handleResize); }; } }, [setFileViewerRect, inline]); const hidePlayer = !isPlaying || !uri || (!inline && (!floatingPlayerEnabled || !isStreamable)); if (hidePlayer) { // clearPlayingUri(); return null; } return (
{!inline && (
)} {isReadyToPlay ? : } {!inline && (
{title || uri}
)}
); }