2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2018-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-04-12 20:23:26 +00:00
|
|
|
import React from 'react';
|
2018-07-18 00:15:34 +00:00
|
|
|
import classNames from 'classnames';
|
2018-04-12 20:23:26 +00:00
|
|
|
|
|
|
|
import moment from 'moment';
|
|
|
|
import formatFileSize from 'filesize';
|
|
|
|
|
|
|
|
interface Props {
|
2018-05-08 19:56:10 +00:00
|
|
|
// Required
|
|
|
|
timestamp: number;
|
|
|
|
|
|
|
|
// Optional
|
2019-01-14 21:49:58 +00:00
|
|
|
fileName?: string;
|
2018-04-12 20:23:26 +00:00
|
|
|
fileSize?: number;
|
2018-04-15 06:16:39 +00:00
|
|
|
onClick?: () => void;
|
2018-05-08 19:56:10 +00:00
|
|
|
shouldShowSeparator?: boolean;
|
2018-04-12 20:23:26 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 19:31:43 +00:00
|
|
|
export class DocumentListItem extends React.Component<Props> {
|
2018-05-08 19:56:10 +00:00
|
|
|
public static defaultProps: Partial<Props> = {
|
|
|
|
shouldShowSeparator: true,
|
|
|
|
};
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public render(): JSX.Element {
|
2018-05-08 19:56:10 +00:00
|
|
|
const { shouldShowSeparator } = this.props;
|
2018-05-22 19:31:43 +00:00
|
|
|
|
2018-05-08 19:56:10 +00:00
|
|
|
return (
|
|
|
|
<div
|
2018-07-18 00:15:34 +00:00
|
|
|
className={classNames(
|
|
|
|
'module-document-list-item',
|
|
|
|
shouldShowSeparator
|
|
|
|
? 'module-document-list-item--with-separator'
|
|
|
|
: null
|
|
|
|
)}
|
2018-05-08 19:56:10 +00:00
|
|
|
>
|
|
|
|
{this.renderContent()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private renderContent() {
|
2020-09-14 19:51:27 +00:00
|
|
|
const { fileName, fileSize, onClick, timestamp } = this.props;
|
2018-04-12 20:23:26 +00:00
|
|
|
|
|
|
|
return (
|
2019-11-07 21:36:16 +00:00
|
|
|
<button
|
2020-09-14 19:51:27 +00:00
|
|
|
type="button"
|
2018-07-18 00:15:34 +00:00
|
|
|
className="module-document-list-item__content"
|
2020-09-14 19:51:27 +00:00
|
|
|
onClick={onClick}
|
2018-05-22 19:31:43 +00:00
|
|
|
>
|
2018-07-18 00:15:34 +00:00
|
|
|
<div className="module-document-list-item__icon" />
|
|
|
|
<div className="module-document-list-item__metadata">
|
|
|
|
<span className="module-document-list-item__file-name">
|
|
|
|
{fileName}
|
|
|
|
</span>
|
|
|
|
<span className="module-document-list-item__file-size">
|
2020-10-21 23:54:53 +00:00
|
|
|
{typeof fileSize === 'number'
|
|
|
|
? formatFileSize(fileSize, { round: 0 })
|
|
|
|
: ''}
|
2018-04-12 20:23:26 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
2018-07-18 00:15:34 +00:00
|
|
|
<div className="module-document-list-item__date">
|
2018-04-12 21:22:26 +00:00
|
|
|
{moment(timestamp).format('ddd, MMM D, Y')}
|
2018-04-12 20:23:26 +00:00
|
|
|
</div>
|
2019-11-07 21:36:16 +00:00
|
|
|
</button>
|
2018-04-12 20:23:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|