import React from 'react'; import classNames from 'classnames'; import { isImageTypeSupported, isVideoTypeSupported, } from '../../../util/GoogleChrome'; import { Message } from './types/Message'; import { Localizer } from '../../../types/Util'; interface Props { message: Message; onClick?: () => void; i18n: Localizer; } interface State { imageBroken: boolean; } export class MediaGridItem extends React.Component { private onImageErrorBound: () => void; constructor(props: Props) { super(props); this.state = { imageBroken: false, }; this.onImageErrorBound = this.onImageError.bind(this); } public onImageError() { this.setState({ imageBroken: true, }); } public renderContent() { const { message, i18n } = this.props; const { imageBroken } = this.state; const { attachments } = message; if (!attachments || !attachments.length) { return null; } const first = attachments[0]; const { contentType } = first; if (contentType && isImageTypeSupported(contentType)) { if (imageBroken || !message.thumbnailObjectUrl) { return (
); } return ( {i18n('lightboxImageAlt')} ); } else if (contentType && isVideoTypeSupported(contentType)) { if (imageBroken || !message.thumbnailObjectUrl) { return (
); } return (
{i18n('lightboxImageAlt')}
); } return (
); } public render() { return (
{this.renderContent()}
); } }