import React, { useContext } from 'react'; import classNames from 'classnames'; import { areAllAttachmentsVisual, AttachmentType, AttachmentTypeWithPath, getAlt, getImageDimensionsInAttachment, getThumbnailUrl, isVideoAttachment, } from '../../types/Attachment'; import { Image } from './Image'; import { IsMessageVisibleContext } from './message/message-content/MessageContent'; type Props = { attachments: Array; bottomOverlay?: boolean; onError: () => void; onClickAttachment?: (attachment: AttachmentTypeWithPath | AttachmentType) => void; }; // tslint:disable: cyclomatic-complexity max-func-body-length use-simple-attributes export const ImageGrid = (props: Props) => { const { attachments, bottomOverlay, onError, onClickAttachment } = props; const isMessageVisible = useContext(IsMessageVisibleContext); const withBottomOverlay = Boolean(bottomOverlay); if (!attachments || !attachments.length) { return null; } if (attachments.length === 1 || !areAllAttachmentsVisual(attachments)) { const { height, width } = getImageDimensionsInAttachment(attachments[0]); return (
{getAlt(attachments[0])}
); } if (attachments.length === 2) { return (
{getAlt(attachments[0])} {getAlt(attachments[1])}
); } if (attachments.length === 3) { return (
{getAlt(attachments[0])}
{getAlt(attachments[1])} {getAlt(attachments[2])}
); } if (attachments.length === 4) { return (
{getAlt(attachments[0])} {getAlt(attachments[1])}
{getAlt(attachments[2])} {getAlt(attachments[3])}
); } const moreMessagesOverlay = attachments.length > 5; const moreMessagesOverlayText = moreMessagesOverlay ? `+${attachments.length - 5}` : undefined; return (
{getAlt(attachments[0])} {getAlt(attachments[1])}
{getAlt(attachments[2])} {getAlt(attachments[3])} {getAlt(attachments[4])}
); };