diff --git a/web/media/multimedia-modal.react.js b/web/media/multimedia-modal.react.js --- a/web/media/multimedia-modal.react.js +++ b/web/media/multimedia-modal.react.js @@ -1,21 +1,14 @@ // @flow -import invariant from 'invariant'; import * as React from 'react'; -import { XCircle as XCircleIcon } from 'react-feather'; -import { useModalContext } from 'lib/components/modal-provider.react.js'; -import { fetchableMediaURI } from 'lib/media/media-utils.js'; import type { EncryptedMediaType, MediaType, Dimensions, } from 'lib/types/media-types.js'; -import EncryptedMultimedia from './encrypted-multimedia.react.js'; -import LoadableVideo from './loadable-video.react.js'; -import { usePlaceholder } from './media-utils.js'; -import css from './media.css'; +import FullScreenViewModal from '../modals/full-screen-view-modal.react.js'; type MediaInfo = | { @@ -35,174 +28,12 @@ +thumbnailEncryptionKey: ?string, }; -type BaseProps = { - +media: MediaInfo, -}; - type Props = { - ...BaseProps, - +popModal: (modal: ?React.Node) => void, - +placeholderImage: ?string, -}; - -type State = { - +dimensions: ?Dimensions, + +media: MediaInfo, }; -class MultimediaModal extends React.PureComponent { - overlay: ?HTMLDivElement; - - constructor(props: Props) { - super(props); - this.state = { dimensions: null }; - } - - componentDidMount() { - invariant(this.overlay, 'overlay ref unset'); - this.overlay.focus(); - this.calculateMediaDimensions(); - window.addEventListener('resize', this.calculateMediaDimensions); - } - - componentWillUnmount() { - window.removeEventListener('resize', this.calculateMediaDimensions); - } - - render(): React.Node { - let mediaModalItem; - const { media, placeholderImage } = this.props; - const style = { - backgroundImage: placeholderImage - ? `url(${placeholderImage})` - : undefined, - }; - if (media.type === 'photo') { - const uri = fetchableMediaURI(media.uri); - mediaModalItem = ; - } else if (media.type === 'video') { - const uri = fetchableMediaURI(media.uri); - const { thumbnailURI } = media; - invariant(thumbnailURI, 'video missing thumbnail'); - mediaModalItem = ( - - ); - } else { - invariant( - media.type === 'encrypted_photo' || media.type === 'encrypted_video', - 'invalid media type', - ); - const { - type, - blobURI, - encryptionKey, - thumbnailBlobURI, - thumbnailEncryptionKey, - } = media; - const dimensions = this.state.dimensions ?? media.dimensions; - const elementStyle = dimensions - ? { - width: `${dimensions.width}px`, - height: `${dimensions.height}px`, - } - : undefined; - mediaModalItem = ( - - ); - } - - return ( -
-
- {mediaModalItem} -
- -
- ); - } - - overlayRef: (overlay: ?HTMLDivElement) => void = overlay => { - this.overlay = overlay; - }; - - onBackgroundClick: (event: SyntheticEvent) => void = - event => { - if (event.target === this.overlay) { - this.props.popModal(); - } - }; - - onKeyDown: (event: SyntheticKeyboardEvent) => void = - event => { - if (event.key === 'Escape') { - this.props.popModal(); - } - }; - - calculateMediaDimensions: () => void = () => { - if (!this.overlay || !this.props.media.dimensions) { - return; - } - const containerWidth = this.overlay.clientWidth; - const containerHeight = this.overlay.clientHeight; - const containerAspectRatio = containerWidth / containerHeight; - - const { width: mediaWidth, height: mediaHeight } = - this.props.media.dimensions; - const mediaAspectRatio = mediaWidth / mediaHeight; - - let newWidth, newHeight; - if (containerAspectRatio > mediaAspectRatio) { - newWidth = Math.min(mediaWidth, containerHeight * mediaAspectRatio); - newHeight = newWidth / mediaAspectRatio; - } else { - newHeight = Math.min(mediaHeight, containerWidth / mediaAspectRatio); - newWidth = newHeight * mediaAspectRatio; - } - this.setState({ - dimensions: { - width: newWidth, - height: newHeight, - }, - }); - }; -} - -function ConnectedMultiMediaModal(props: BaseProps): React.Node { - const modalContext = useModalContext(); - const { thumbHash, encryptionKey, thumbnailEncryptionKey } = props.media; - const thumbHashEncryptionKey = thumbnailEncryptionKey ?? encryptionKey; - const placeholderImage = usePlaceholder(thumbHash, thumbHashEncryptionKey); - - return ( - - ); +function MultimediaModal(props: Props): React.Node { + return ; } -export default ConnectedMultiMediaModal; +export default MultimediaModal; diff --git a/web/media/multimedia-modal.react.js b/web/modals/full-screen-view-modal.react.js copy from web/media/multimedia-modal.react.js copy to web/modals/full-screen-view-modal.react.js --- a/web/media/multimedia-modal.react.js +++ b/web/modals/full-screen-view-modal.react.js @@ -12,10 +12,10 @@ Dimensions, } from 'lib/types/media-types.js'; -import EncryptedMultimedia from './encrypted-multimedia.react.js'; -import LoadableVideo from './loadable-video.react.js'; -import { usePlaceholder } from './media-utils.js'; -import css from './media.css'; +import EncryptedMultimedia from '../media/encrypted-multimedia.react.js'; +import css from '../media/full-screen-view-modal.css'; +import LoadableVideo from '../media/loadable-video.react.js'; +import { usePlaceholder } from '../media/media-utils.js'; type MediaInfo = | {