2015-03-21 01:23:50 +08:00
|
|
|
_ = require 'underscore-plus'
|
|
|
|
React = require 'react'
|
2015-05-15 08:08:30 +08:00
|
|
|
{Actions, Message, DraftStore} = require 'nylas-exports'
|
2015-03-21 01:23:50 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
class TemplateStatusBar extends React.Component
|
|
|
|
@displayName: 'TemplateStatusBar'
|
2015-03-21 01:23:50 +08:00
|
|
|
|
feat(unsafe-components): Wrap injected components, catch exceptions, clean up ComponentRegistry
Summary:
This diff gives the ComponentRegistry a cleaner, smaller API. Instead of querying by name, location or role,
it's now just location and role, and you can register components for one or more location and one or more
roles without assigning the entries in the registry separate names.
When you register with the ComponentRegistry, the syntax is also cleaner and uses the component's displayName
instead of requiring you to provide a name. You also provide the actual component when unregistering, ensuring
that you can't unregister someone else's component.
InjectedComponent and InjectedComponentSet now wrap their children in UnsafeComponent, which prevents
render/component lifecycle problems from propogating.
Existing components have been updated:
1. maxWidth / minWidth are now containerStyles.maxWidth/minWidth
2. displayName is now required to use the CR.
3. containerRequired = false can be provided to exempt a component from being wrapped in an UnsafeComponent.
This is useful because it's slightly faster and keeps DOM flat.
This diff also makes the "Show Component Regions" more awesome. It displays column regions, since they now
use the InjectedComponentSet, and also shows for InjectedComponent as well as InjectedComponentSet.
Change ComponentRegistry syntax, lots more work on safely wrapping items. See description.
Fix for inline flexbox scenarios (message actions)
Allow ~/.inbox/packages to be symlinked to a github repo
Test Plan: Run tests!
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1457
2015-05-01 07:10:15 +08:00
|
|
|
@containerStyles:
|
|
|
|
textAlign:'center'
|
|
|
|
width:530
|
|
|
|
margin:'auto'
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
@propTypes:
|
2015-03-21 01:23:50 +08:00
|
|
|
draftLocalId: React.PropTypes.string
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
constructor: (@props) ->
|
|
|
|
@state = draft: null
|
2015-03-21 01:23:50 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
componentDidMount: =>
|
2015-05-16 01:45:18 +08:00
|
|
|
DraftStore.sessionForLocalId(@props.draftLocalId).then (_proxy) =>
|
|
|
|
return if @_unmounted
|
|
|
|
return unless _proxy.draftLocalId is @props.draftLocalId
|
|
|
|
@_proxy = _proxy
|
|
|
|
@unsubscribe = @_proxy.listen(@_onDraftChange, @)
|
2015-03-21 01:23:50 +08:00
|
|
|
@_onDraftChange()
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
componentWillUnmount: =>
|
2015-05-16 01:45:18 +08:00
|
|
|
@_unmounted = true
|
2015-03-21 01:23:50 +08:00
|
|
|
@unsubscribe() if @unsubscribe
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
render: =>
|
2015-03-21 01:23:50 +08:00
|
|
|
if @_draftUsesTemplate()
|
|
|
|
<div className="template-status-bar">
|
|
|
|
Press "tab" to quickly fill in the blanks - highlighting will not be visible to recipients.
|
|
|
|
</div>
|
|
|
|
else
|
|
|
|
<div></div>
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_onDraftChange: =>
|
2015-03-21 01:23:50 +08:00
|
|
|
@setState(draft: @_proxy.draft())
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_draftUsesTemplate: =>
|
2015-03-21 01:23:50 +08:00
|
|
|
return unless @state.draft
|
|
|
|
@state.draft.body.search(/<code[^>]*class="var[^>]*>/i) > 0
|
2015-05-01 04:08:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = TemplateStatusBar
|