// Copyright 2018-2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import { DocumentListItem } from './DocumentListItem'; import { ItemClickEvent } from './types/ItemClickEvent'; import { MediaGridItem } from './MediaGridItem'; import { MediaItemType } from '../../LightboxGallery'; import { missingCaseError } from '../../../util/missingCaseError'; import { LocalizerType } from '../../../types/Util'; import { getMessageTimestamp } from '../../../util/getMessageTimestamp'; export type Props = { i18n: LocalizerType; header?: string; type: 'media' | 'documents'; mediaItems: Array; onItemClick?: (event: ItemClickEvent) => void; }; export class AttachmentSection extends React.Component { public render(): JSX.Element { const { header } = this.props; return (

{header}

{this.renderItems()}
); } private renderItems() { const { i18n, mediaItems, type } = this.props; return mediaItems.map((mediaItem, position, array) => { const shouldShowSeparator = position < array.length - 1; const { message, index, attachment } = mediaItem; const onClick = this.createClickHandler(mediaItem); switch (type) { case 'media': return ( ); case 'documents': return ( ); default: return missingCaseError(type); } }); } private readonly createClickHandler = (mediaItem: MediaItemType) => () => { const { onItemClick, type } = this.props; const { message, attachment } = mediaItem; if (!onItemClick) { return; } onItemClick({ type, message, attachment }); }; }