feat(sidebar): add timestamps to related messages

This commit is contained in:
Evan Morikawa 2016-03-09 16:17:20 -05:00
parent 8475afbbfb
commit 89323b05db
5 changed files with 30 additions and 15 deletions

View file

@ -19,11 +19,12 @@ class MessageTimestamp extends React.Component
nowDate = @_today() nowDate = @_today()
formattedDate = @_formattedDate(msgDate, nowDate, @props.isDetailed) formattedDate = @_formattedDate(msgDate, nowDate, @props.isDetailed)
<div className={@props.className} <div className={@props.className}
title={Utils.fullTimeString(@props.date)}
onClick={@props.onClick}>{formattedDate}</div> onClick={@props.onClick}>{formattedDate}</div>
_formattedDate: (msgDate, now, isDetailed) => _formattedDate: (msgDate, now, isDetailed) =>
if isDetailed if isDetailed
return msgDate.format "MMMM D, YYYY [at] h:mm A" return msgDate.format "MMMM D, YYYY [at] h:mm A z"
else else
diff = now.diff(msgDate, 'days', true) diff = now.diff(msgDate, 'days', true)
isSameDay = now.isSame(msgDate, 'days') isSameDay = now.isSame(msgDate, 'days')

View file

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import {Actions} from 'nylas-exports' import {Utils, Actions} from 'nylas-exports'
export default class RelatedThreads extends React.Component { export default class RelatedThreads extends React.Component {
static displayName = "RelatedThreads"; static displayName = "RelatedThreads";
@ -53,7 +53,8 @@ export default class RelatedThreads extends React.Component {
const onClick = () => { this._onClick(thread) } const onClick = () => { this._onClick(thread) }
return ( return (
<div key={thread.id} className="related-thread" onClick={onClick} > <div key={thread.id} className="related-thread" onClick={onClick} >
{thread.subject} <span className="subject" title={thread.subject}>{thread.subject}</span>
<span className="timestamp" title={Utils.fullTimeString(thread.lastMessageReceivedTimestamp)}>{Utils.shortTimeString(thread.lastMessageReceivedTimestamp)}</span>
</div> </div>
) )
}) })

View file

@ -13,14 +13,20 @@
border-radius: 0 0 @border-radius-large @border-radius-large; border-radius: 0 0 @border-radius-large @border-radius-large;
.related-thread { .related-thread {
display: flex;
font-size: 12px; font-size: 12px;
color: #566f86; color: #566f86;
width: 100%; width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
padding: 0.5em 15px; padding: 0.5em 15px;
border-top: 1px solid rgba(0,0,0,0.08); border-top: 1px solid rgba(0,0,0,0.08);
.subject {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
padding-right: 1em;
}
} }
.toggle { .toggle {

View file

@ -1,16 +1,9 @@
moment = require "moment" {Utils} = require 'nylas-exports'
React = require 'react' React = require 'react'
module.exports = module.exports =
timestamp: (time) -> timestamp: (time) ->
diff = moment().diff(time, 'days', true) Utils.shortTimeString(time)
if diff <= 1
format = "h:mm a"
else if diff > 1 and diff <= 365
format = "MMM D"
else
format = "MMM D YYYY"
moment(time).format(format)
subject: (subj) -> subject: (subj) ->
if (subj ? "").trim().length is 0 if (subj ? "").trim().length is 0

View file

@ -1,6 +1,7 @@
_ = require 'underscore' _ = require 'underscore'
fs = require('fs-plus') fs = require('fs-plus')
path = require('path') path = require('path')
moment = require('moment-timezone')
tz = Intl.DateTimeFormat().resolvedOptions().timeZone tz = Intl.DateTimeFormat().resolvedOptions().timeZone
TaskRegistry = null TaskRegistry = null
@ -37,6 +38,19 @@ Utils =
timeZone: tz timeZone: tz
shortTimeString: (time) ->
diff = moment().diff(time, 'days', true)
if diff <= 1
format = "h:mm a"
else if diff > 1 and diff <= 365
format = "MMM D"
else
format = "MMM D YYYY"
moment(time).format(format)
fullTimeString: (time) ->
moment(time).tz(Utils.timeZone).format("dddd, MMMM Do YYYY, h:mm:ss a z")
isHash: (object) -> isHash: (object) ->
_.isObject(object) and not _.isFunction(object) and not _.isArray(object) _.isObject(object) and not _.isFunction(object) and not _.isArray(object)