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

View File

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