2018-12-02 01:48:53 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import {
|
|
|
|
isImageTypeSupported,
|
|
|
|
isVideoTypeSupported,
|
|
|
|
} from '../../util/GoogleChrome';
|
|
|
|
import { Image } from './Image';
|
|
|
|
import { StagedGenericAttachment } from './StagedGenericAttachment';
|
2019-01-15 17:33:23 +00:00
|
|
|
import { StagedPlaceholderAttachment } from './StagedPlaceholderAttachment';
|
2019-01-14 21:49:58 +00:00
|
|
|
import { LocalizerType } from '../../types/Util';
|
|
|
|
import {
|
|
|
|
areAllAttachmentsVisual,
|
|
|
|
AttachmentType,
|
|
|
|
getUrl,
|
|
|
|
isVideoAttachment,
|
|
|
|
} from '../../types/Attachment';
|
2018-12-02 01:48:53 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
attachments: Array<AttachmentType>;
|
2019-01-14 21:49:58 +00:00
|
|
|
i18n: LocalizerType;
|
2018-12-02 01:48:53 +00:00
|
|
|
// onError: () => void;
|
|
|
|
onClickAttachment: (attachment: AttachmentType) => void;
|
|
|
|
onCloseAttachment: (attachment: AttachmentType) => void;
|
2019-01-15 17:33:23 +00:00
|
|
|
onAddAttachment: () => void;
|
2018-12-02 01:48:53 +00:00
|
|
|
onClose: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const IMAGE_WIDTH = 120;
|
|
|
|
const IMAGE_HEIGHT = 120;
|
|
|
|
|
|
|
|
export class AttachmentList extends React.Component<Props> {
|
|
|
|
// tslint:disable-next-line max-func-body-length */
|
|
|
|
public render() {
|
|
|
|
const {
|
|
|
|
attachments,
|
|
|
|
i18n,
|
2019-01-15 17:33:23 +00:00
|
|
|
onAddAttachment,
|
2018-12-02 01:48:53 +00:00
|
|
|
onClickAttachment,
|
|
|
|
onCloseAttachment,
|
|
|
|
onClose,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!attachments.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-15 17:33:23 +00:00
|
|
|
const allVisualAttachments = areAllAttachmentsVisual(attachments);
|
|
|
|
|
2018-12-02 01:48:53 +00:00
|
|
|
return (
|
|
|
|
<div className="module-attachments">
|
|
|
|
{attachments.length > 1 ? (
|
|
|
|
<div className="module-attachments__header">
|
2019-11-07 21:36:16 +00:00
|
|
|
<button
|
2018-12-02 01:48:53 +00:00
|
|
|
onClick={onClose}
|
|
|
|
className="module-attachments__close-button"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
<div className="module-attachments__rail">
|
|
|
|
{(attachments || []).map((attachment, index) => {
|
|
|
|
const { contentType } = attachment;
|
|
|
|
if (
|
|
|
|
isImageTypeSupported(contentType) ||
|
|
|
|
isVideoTypeSupported(contentType)
|
|
|
|
) {
|
2019-01-14 21:49:58 +00:00
|
|
|
const imageKey =
|
|
|
|
getUrl(attachment) || attachment.fileName || index;
|
|
|
|
const clickCallback =
|
|
|
|
attachments.length > 1 ? onClickAttachment : undefined;
|
|
|
|
|
2018-12-02 01:48:53 +00:00
|
|
|
return (
|
|
|
|
<Image
|
2019-01-14 21:49:58 +00:00
|
|
|
key={imageKey}
|
2019-01-10 20:26:28 +00:00
|
|
|
alt={i18n('stagedImageAttachment', [
|
|
|
|
getUrl(attachment) || attachment.fileName,
|
|
|
|
])}
|
2018-12-02 01:48:53 +00:00
|
|
|
i18n={i18n}
|
|
|
|
attachment={attachment}
|
|
|
|
softCorners={true}
|
|
|
|
playIconOverlay={isVideoAttachment(attachment)}
|
|
|
|
height={IMAGE_HEIGHT}
|
|
|
|
width={IMAGE_WIDTH}
|
|
|
|
url={getUrl(attachment)}
|
|
|
|
closeButton={true}
|
2019-01-14 21:49:58 +00:00
|
|
|
onClick={clickCallback}
|
2018-12-02 01:48:53 +00:00
|
|
|
onClickClose={onCloseAttachment}
|
2019-08-07 00:40:25 +00:00
|
|
|
onError={() => {
|
|
|
|
onCloseAttachment(attachment);
|
|
|
|
}}
|
2018-12-02 01:48:53 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
const genericKey =
|
|
|
|
getUrl(attachment) || attachment.fileName || index;
|
|
|
|
|
2018-12-02 01:48:53 +00:00
|
|
|
return (
|
|
|
|
<StagedGenericAttachment
|
2019-01-14 21:49:58 +00:00
|
|
|
key={genericKey}
|
2018-12-02 01:48:53 +00:00
|
|
|
attachment={attachment}
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={onCloseAttachment}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
2019-01-15 17:33:23 +00:00
|
|
|
{allVisualAttachments ? (
|
2019-11-07 21:36:16 +00:00
|
|
|
<StagedPlaceholderAttachment
|
|
|
|
onClick={onAddAttachment}
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
2019-01-15 17:33:23 +00:00
|
|
|
) : null}
|
2018-12-02 01:48:53 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|