Mailspring/app/internal_packages/message-list/lib/message-timestamp.jsx

37 lines
941 B
React
Raw Normal View History

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