fix(msg-timestamp): Fix incorrect date var / convert to es6

- Typo in cjsx code broke the message timestamp
- Converted to es6 so this doesn't happen again!
This commit is contained in:
Juan Tejada 2016-08-18 18:11:52 -07:00
parent 5cbe1f4007
commit 6c00098861
5 changed files with 43 additions and 32 deletions

View file

@ -4,7 +4,7 @@ _ = require 'underscore'
EmailFrame = require('./email-frame').default
MessageParticipants = require "./message-participants"
MessageItemBody = require "./message-item-body"
MessageTimestamp = require "./message-timestamp"
MessageTimestamp = require("./message-timestamp").default
MessageControls = require './message-controls'
{Utils,
Actions,

View file

@ -1,29 +0,0 @@
_ = require 'underscore'
moment = require 'moment-timezone'
React = require 'react'
{DateUtils} = require 'nylas-exports'
class MessageTimestamp extends React.Component
@displayName: 'MessageTimestamp'
@propTypes:
date: React.PropTypes.object.isRequired,
className: React.PropTypes.string,
isDetailed: React.PropTypes.bool
onClick: React.PropTypes.func
shouldComponentUpdate: (nextProps, nextState) =>
+nextProps.date isnt +@props.date or nextProps.isDetailed isnt @props.isDetailed
render: =>
if @props.isDetailed
formattedDate = DateUtils.mediumTimeString(@props.date)
else
fromattedDate = DateUtils.shortTimeString(@props.date)
<div className={@props.className}
title={DateUtils.fullTimeString(@props.date)}
onClick={@props.onClick}>{formattedDate}</div>
# Stubbable for testing. Returns a `moment`
_today: -> moment.tz(DateUtils.timeZone)
module.exports = MessageTimestamp

View file

@ -0,0 +1,40 @@
import React from 'react'
import {DateUtils} from 'nylas-exports'
class MessageTimestamp extends React.Component {
static displayName = 'MessageTimestamp'
static propTypes = {
date: React.PropTypes.object.isRequired,
className: React.PropTypes.string,
isDetailed: React.PropTypes.bool,
onClick: React.PropTypes.func,
}
shouldComponentUpdate(nextProps) {
return (
nextProps.date !== this.props.date ||
nextProps.isDetailed !== this.props.isDetailed
)
}
render() {
let formattedDate = null
if (this.props.isDetailed) {
formattedDate = DateUtils.mediumTimeString(this.props.date)
} else {
formattedDate = DateUtils.shortTimeString(this.props.date)
}
return (
<div
className={this.props.className}
title={DateUtils.fullTimeString(this.props.date)}
onClick={this.props.onClick}
>
{formattedDate}
</div>
)
}
}
export default MessageTimestamp

View file

@ -86,7 +86,7 @@ user_5 = new Contact
MessageItem = proxyquire '../lib/message-item',
'./message-item-body': MessageItemBody
MessageTimestamp = require '../lib/message-timestamp'
MessageTimestamp = require('../lib/message-timestamp').default
describe "MessageItem", ->

View file

@ -2,7 +2,7 @@ moment = require 'moment'
React = require "react"
ReactDOM = require "react-dom"
ReactTestUtils = require 'react-addons-test-utils'
MessageTimestamp = require '../lib/message-timestamp'
MessageTimestamp = require('../lib/message-timestamp').default
msgTime = ->
moment([2010, 1, 14, 15, 25, 50, 125]) # Feb 14, 2010 at 3:25 PM