From 2abde9186c87cf7c691b07e9241f783c9a568570 Mon Sep 17 00:00:00 2001 From: Ahmad Karlam Date: Sun, 4 Oct 2020 09:08:05 +0700 Subject: [PATCH] refactoring --- webroot/js/components/chat/message.js | 26 +++++++------------------- webroot/js/utils/chat.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/webroot/js/components/chat/message.js b/webroot/js/components/chat/message.js index 2e5fc7695..317a9006a 100644 --- a/webroot/js/components/chat/message.js +++ b/webroot/js/components/chat/message.js @@ -1,25 +1,13 @@ -import {Component, h} from 'https://unpkg.com/preact?module'; +import { h, Component } from 'https://unpkg.com/preact?module'; import htm from 'https://unpkg.com/htm?module'; -import {messageBubbleColorForString} from '../../utils/user-colors.js'; -import {formatMessageText} from '../../utils/chat.js'; -import {generateAvatar} from '../../utils/helpers.js'; -import {SOCKET_MESSAGE_TYPES} from '../../utils/websocket.js'; - const html = htm.bind(h); +import { messageBubbleColorForString } from '../../utils/user-colors.js'; +import { formatMessageText, formatTimestamp } from '../../utils/chat.js'; +import { generateAvatar } from '../../utils/helpers.js'; +import { SOCKET_MESSAGE_TYPES } from '../../utils/websocket.js'; + export default class Message extends Component { - formatTimestamp(sentAt) { - sentAt = new Date(sentAt); - - let diffInDays = ((new Date()) - sentAt) / (24 * 3600 * 1000); - if (diffInDays >= -1) { - return `${sentAt.toLocaleDateString('en-US', {dateStyle: 'medium'})} at ` + - sentAt.toLocaleTimeString(); - } - - return sentAt.toLocaleTimeString(); - } - render(props) { const { message, username } = props; const { type } = message; @@ -47,7 +35,7 @@ export default class Message extends Component {
= -1) { + return `${sentAt.toLocaleDateString('en-US', {dateStyle: 'medium'})} at ` + + sentAt.toLocaleTimeString(); + } + + return sentAt.toLocaleTimeString(); +}