import React, { Suspense } from 'react'; import { openModal } from 'soapbox/actions/modals'; import AttachmentThumbs from 'soapbox/components/attachment-thumbs'; import PreviewCard from 'soapbox/components/preview-card'; import PlaceholderCard from 'soapbox/features/placeholder/components/placeholder-card'; import { MediaGallery, Video, Audio } from 'soapbox/features/ui/util/async-components'; import { useAppDispatch, useSettings } from 'soapbox/hooks'; import { defaultMediaVisibility } from 'soapbox/utils/status'; import type { List as ImmutableList } from 'immutable'; import type { Status, Attachment } from 'soapbox/types/entities'; interface IStatusMedia { /** Status entity to render media for. */ status: Status; /** Whether to display compact media. */ muted?: boolean; /** Callback when compact media is clicked. */ onClick?: () => void; /** Whether or not the media is concealed behind a NSFW banner. */ showMedia?: boolean; } /** Render media attachments for a status. */ const StatusMedia: React.FC = ({ status, muted = false, onClick, showMedia, }) => { const dispatch = useAppDispatch(); const { displayMedia } = useSettings(); const visible = showMedia || (status.hidden === null ? defaultMediaVisibility(status, displayMedia) : status.hidden); const size = status.media_attachments.size; const firstAttachment = status.media_attachments.first(); let media: JSX.Element | null = null; const renderLoadingMediaGallery = (): JSX.Element => { return
; }; const renderLoadingVideoPlayer = (): JSX.Element => { return
; }; const renderLoadingAudioPlayer = (): JSX.Element => { return
; }; const openMedia = (media: ImmutableList, index: number) => { dispatch(openModal('MEDIA', { media, status, index })); }; if (size > 0 && firstAttachment) { if (muted) { media = ( ); } else if (size === 1 && firstAttachment.type === 'video') { const video = firstAttachment; media = ( ); } else if (size === 1 && firstAttachment.type === 'audio') { const attachment = firstAttachment; media = ( ); } else { media = ( ); } } else if (status.spoiler_text.length === 0 && !status.quote && status.card) { media = ( ); } else if (status.expectsCard) { media = ( ); } if (media) { return ( // eslint-disable-next-line jsx-a11y/no-static-element-interactions
e.stopPropagation()}> {media}
); } else { return null; } }; export default StatusMedia;