_ = require 'underscore' path = require 'path' React = require 'react' {RetinaImg} = require 'nylas-component-kit' {Actions, DateUtils, Message, Event, ComponentRegistry, EventRSVPTask, DatabaseStore, AccountStore} = require 'nylas-exports' moment = require 'moment-timezone' class EventHeader extends React.Component @displayName: 'EventHeader' @propTypes: message: React.PropTypes.instanceOf(Message).isRequired constructor: (@props) -> @state = event: @props.message.events[0] _onChange: => return unless @state.event DatabaseStore.find(Event, @state.event.id).then (event) => return unless event @setState({event}) componentDidMount: => # TODO: This should use observables! @_unlisten = DatabaseStore.listen (change) => if @state.event and change.objectClass is Event.name updated = _.find change.objects, (o) => o.id is @state.event.id @setState({event: updated}) if updated @_onChange() componentWillReceiveProps: (nextProps) => @setState({event:nextProps.message.events[0]}) @_onChange() componentWillUnmount: => @_unlisten?() render: => timeFormat = DateUtils.getTimeFormat({timeZone: true}) if @state.event?