You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.7 KiB
TypeScript
74 lines
1.7 KiB
TypeScript
7 years ago
|
/**
|
||
|
* @prettier
|
||
|
*/
|
||
7 years ago
|
import React from 'react';
|
||
|
|
||
7 years ago
|
import { DocumentListItem } from './DocumentListItem';
|
||
|
import { MediaGridItem } from './MediaGridItem';
|
||
7 years ago
|
import { Message } from './propTypes/Message';
|
||
7 years ago
|
import { missingCaseError } from '../../../util/missingCaseError';
|
||
7 years ago
|
|
||
7 years ago
|
const styles = {
|
||
|
container: {
|
||
|
width: '100%',
|
||
|
},
|
||
7 years ago
|
header: {
|
||
|
fontSize: 14,
|
||
|
fontWeight: 'normal',
|
||
|
lineHeight: '28px',
|
||
|
} as React.CSSProperties,
|
||
7 years ago
|
itemContainer: {
|
||
|
display: 'flex',
|
||
|
flexDirection: 'row',
|
||
|
flexWrap: 'wrap',
|
||
|
justifyContent: 'flex-start',
|
||
|
alignItems: 'flex-start',
|
||
|
} as React.CSSProperties,
|
||
|
};
|
||
|
|
||
|
interface Props {
|
||
|
i18n: (value: string) => string;
|
||
|
header?: string;
|
||
|
type: 'media' | 'documents';
|
||
|
messages: Array<Message>;
|
||
|
}
|
||
|
|
||
7 years ago
|
export class AttachmentSection extends React.Component<Props, {}> {
|
||
7 years ago
|
public renderItems() {
|
||
|
const { i18n, messages, type } = this.props;
|
||
7 years ago
|
|
||
7 years ago
|
return messages.map(message => {
|
||
7 years ago
|
const { attachments } = message;
|
||
|
const firstAttachment = attachments[0];
|
||
|
|
||
|
switch (type) {
|
||
|
case 'media':
|
||
7 years ago
|
return <MediaGridItem key={message.received_at} message={message} />;
|
||
7 years ago
|
case 'documents':
|
||
|
return (
|
||
7 years ago
|
<DocumentListItem
|
||
7 years ago
|
key={message.received_at}
|
||
7 years ago
|
i18n={i18n}
|
||
|
fileSize={firstAttachment.size}
|
||
|
fileName={firstAttachment.fileName}
|
||
|
timestamp={message.received_at}
|
||
|
/>
|
||
|
);
|
||
|
default:
|
||
|
return missingCaseError(type);
|
||
|
}
|
||
|
});
|
||
7 years ago
|
}
|
||
|
|
||
|
public render() {
|
||
|
const { header } = this.props;
|
||
|
|
||
|
return (
|
||
|
<div style={styles.container}>
|
||
7 years ago
|
<h2 style={styles.header}>{header}</h2>
|
||
7 years ago
|
<div style={styles.itemContainer}>{this.renderItems()}</div>
|
||
7 years ago
|
</div>
|
||
|
);
|
||
|
}
|
||
|
}
|