0

refactor: declare format timestamp as variable for consistency

This commit is contained in:
Ahmad Karlam 2020-10-04 10:57:45 +07:00
parent 1c03e83c31
commit 8c380f118a
2 changed files with 4 additions and 3 deletions

View File

@ -16,6 +16,7 @@ export default class Message extends Component {
const { image, author, body, timestamp } = message;
const formattedMessage = formatMessageText(body, username);
const avatar = image || generateAvatar(author);
const formattedTimestamp = formatTimestamp(timestamp);
const authorColor = messageBubbleColorForString(author);
const avatarBgColor = { backgroundColor: authorColor };
@ -35,7 +36,7 @@ export default class Message extends Component {
</div>
<div
class="message-text text-gray-300 font-normal overflow-y-hidden"
title=${`Sent at ${formatTimestamp(timestamp)}`}
title=${formattedTimestamp}
dangerouslySetInnerHTML=${
{ __html: formattedMessage }
}

View File

@ -284,9 +284,9 @@ export function formatTimestamp(sentAt) {
let diffInDays = ((new Date()) - sentAt) / (24 * 3600 * 1000);
if (diffInDays >= 1) {
return `${sentAt.toLocaleDateString('en-US', {dateStyle: 'medium'})} at ` +
return `Sent at ${sentAt.toLocaleDateString('en-US', {dateStyle: 'medium'})} at ` +
sentAt.toLocaleTimeString();
}
return sentAt.toLocaleTimeString();
return `Sent at ${sentAt.toLocaleTimeString()}`;
}