2017-09-27 02:42:18 +08:00
|
|
|
import { React, PropTypes, DateUtils } from 'mailspring-exports';
|
2016-08-19 09:11:52 +08:00
|
|
|
|
|
|
|
class MessageTimestamp extends React.Component {
|
2017-09-27 02:33:08 +08:00
|
|
|
static displayName = 'MessageTimestamp';
|
2016-08-19 09:11:52 +08:00
|
|
|
|
|
|
|
static propTypes = {
|
2017-09-27 02:33:08 +08:00
|
|
|
date: PropTypes.object.isRequired,
|
|
|
|
className: PropTypes.string,
|
|
|
|
isDetailed: PropTypes.bool,
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
};
|
2016-08-19 09:11:52 +08:00
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps) {
|
2017-09-27 02:33:08 +08:00
|
|
|
return nextProps.date !== this.props.date || nextProps.isDetailed !== this.props.isDetailed;
|
2016-08-19 09:11:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-09-27 02:33:08 +08:00
|
|
|
let formattedDate = null;
|
2016-08-19 09:11:52 +08:00
|
|
|
if (this.props.isDetailed) {
|
2017-09-27 02:33:08 +08:00
|
|
|
formattedDate = DateUtils.mediumTimeString(this.props.date);
|
2016-08-19 09:11:52 +08:00
|
|
|
} else {
|
2017-09-27 02:33:08 +08:00
|
|
|
formattedDate = DateUtils.shortTimeString(this.props.date);
|
2016-08-19 09:11:52 +08:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={this.props.className}
|
|
|
|
title={DateUtils.fullTimeString(this.props.date)}
|
|
|
|
onClick={this.props.onClick}
|
|
|
|
>
|
|
|
|
{formattedDate}
|
|
|
|
</div>
|
2017-09-27 02:33:08 +08:00
|
|
|
);
|
2016-08-19 09:11:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-27 02:33:08 +08:00
|
|
|
export default MessageTimestamp;
|