Browse Source

Remove moment js and use standard library date from javascript

pull/213/head
Ahmad Karlam 5 years ago
parent
commit
d27d4a798f
  1. 3
      webroot/index.html
  2. 23
      webroot/js/components/chat/message.js

3
webroot/index.html

@ -35,9 +35,6 @@ @@ -35,9 +35,6 @@
<script src="//unpkg.com/showdown/dist/showdown.min.js" defer></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@justinribeiro/lite-youtube@0.6.2/lite-youtube.js" defer></script>
<!-- moment js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.0/moment.min.js" integrity="sha512-Izh34nqeeR7/nwthfeE0SI3c8uhFSnqxV0sI9TvTcXiFJkMd6fB644O64BRq2P/LA/+7eRvCw4GmLsXksyTHBg==" crossorigin="anonymous"></script>
<link href="./styles/video.css" rel="stylesheet" />
<link href="./styles/chat.css" rel="stylesheet" />
<link href="./styles/user-content.css" rel="stylesheet" />

23
webroot/js/components/chat/message.js

@ -1,21 +1,23 @@ @@ -1,21 +1,23 @@
import { h, Component } from 'https://unpkg.com/preact?module';
import {Component, h} from 'https://unpkg.com/preact?module';
import htm from 'https://unpkg.com/htm?module';
const html = htm.bind(h);
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';
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);
export default class Message extends Component {
formatTimestamp(sentAt) {
sentAt = moment(sentAt);
sentAt = new Date(sentAt);
if (moment().diff(sentAt, 'days') >= 1) {
return `${sentAt.format('MMM D HH:mm:ss')}`
let diffInDays = ((new Date()) - sentAt) / (24 * 3600 * 1000);
if (diffInDays >= -1) {
return `${sentAt.toLocaleDateString('en-US', {dateStyle: 'medium'})} at ` +
sentAt.toLocaleTimeString();
}
return sentAt.format("HH:mm:ss");
return sentAt.toLocaleTimeString();
}
render(props) {
@ -30,7 +32,6 @@ export default class Message extends Component { @@ -30,7 +32,6 @@ export default class Message extends Component {
const authorColor = messageBubbleColorForString(author);
const avatarBgColor = { backgroundColor: authorColor };
const authorTextColor = { color: authorColor };
return (
html`
<div class="message flex flex-row items-start p-3">

Loading…
Cancel
Save