import React from 'react'; import { isImageTypeSupported, isVideoTypeSupported, } from '../../util/GoogleChrome'; import { AttachmentType } from './types'; import { Image } from './Image'; import { areAllAttachmentsVisual } from './ImageGrid'; import { StagedGenericAttachment } from './StagedGenericAttachment'; import { StagedPlaceholderAttachment } from './StagedPlaceholderAttachment'; import { Localizer } from '../../types/Util'; interface Props { attachments: Array; i18n: Localizer; // onError: () => void; onClickAttachment: (attachment: AttachmentType) => void; onCloseAttachment: (attachment: AttachmentType) => void; onAddAttachment: () => void; onClose: () => void; } const IMAGE_WIDTH = 120; const IMAGE_HEIGHT = 120; export class AttachmentList extends React.Component { // tslint:disable-next-line max-func-body-length */ public render() { const { attachments, i18n, onAddAttachment, onClickAttachment, onCloseAttachment, onClose, } = this.props; if (!attachments.length) { return null; } const allVisualAttachments = areAllAttachmentsVisual(attachments); return (
{attachments.length > 1 ? (
) : null}
{(attachments || []).map((attachment, index) => { const { contentType } = attachment; if ( isImageTypeSupported(contentType) || isVideoTypeSupported(contentType) ) { return ( {i18n('stagedImageAttachment', 1 ? onClickAttachment : undefined } onClickClose={onCloseAttachment} /> ); } return ( ); })} {allVisualAttachments ? ( ) : null}
); } } export function isVideoAttachment(attachment?: AttachmentType) { return ( attachment && attachment.contentType && isVideoTypeSupported(attachment.contentType) ); } function getUrl(attachment: AttachmentType) { if (attachment.screenshot) { return attachment.screenshot.url; } return attachment.url; }