React = require 'react' {Actions} = require 'nylas-exports' NotificationStore = require './notifications-store' class NotificationStickyItem extends React.Component @displayName: "NotificationStickyItem" render: => notif = @props.notification iconClass = if notif.icon then "fa #{notif.icon}" else "" actionDefault = null actionComponents = notif.actions?.map (action) => classname = "action " if action.default actionDefault = action classname += "default" @_fireItemAction(notif, action)}> {action.label} if actionDefault
@_fireItemAction(notif, actionDefault)}> {notif.message}{actionComponents}
else
{notif.message}{actionComponents}
_fireItemAction: (notification, action) => Actions.notificationActionTaken({notification, action}) event.stopPropagation() class NotificationStickyBar extends React.Component @displayName: "NotificationsStickyBar" @containerRequired: false constructor: (@props) -> @state = @_getStateFromStores() _getStateFromStores: => items: NotificationStore.stickyNotifications() _onDataChanged: => @setState @_getStateFromStores() componentDidMount: => @_unlistener = NotificationStore.listen(@_onDataChanged, @) @ # It's important that every React class explicitly stops listening to # atom events before it unmounts. Thank you event-kit # This can be fixed via a Reflux mixin componentWillUnmount: => @_unlistener() if @_unlistener @ render: =>
{@_notificationComponents()}
_notificationComponents: => @state.items.map (notif) -> module.exports = NotificationStickyBar