Mailspring/internal_packages/composer/lib/main.cjsx
Ben Gotow d6336dae08 Squashed commit of deeply broken branch
commit d1c455515e04424d429c87a07aff248a4a767f23
Merge: 72e5536 512f8db
Author: Ben Gotow <bengotow@gmail.com>
Date:   Thu Feb 19 18:42:29 2015 -0800

    Merge sheet and flexbox components, fonts, and more

    Conflicts:
    	static/workspace-view.less

commit 72e553652f5b26a96155c51e04db46baafb916be
Author: Ben Gotow <bengotow@gmail.com>
Date:   Wed Feb 18 12:33:08 2015 -0800

    Start transitioning to a better set of ui-variables (from bootstrap)

commit ed22fb7fe1c6544af44fae69b83e7e63965ddf4d
Author: Ben Gotow <bengotow@gmail.com>
Date:   Wed Feb 18 11:55:58 2015 -0800

    I hate CSS

commit 512f8db414ceef74712c9d63ba5a67b44cf778c4
Author: Ben Gotow <bengotow@gmail.com>
Date:   Mon Feb 16 10:10:44 2015 -0800

    Initial work on top toolbar

commit c2d7a0e0a2f6f6ebe254cca24ad0735336d57b70
Author: Ben Gotow <bengotow@gmail.com>
Date:   Thu Feb 12 18:47:26 2015 -0800

    New UI Prototype interaction / stores for sheets
2015-03-03 09:49:15 -08:00

80 lines
2.9 KiB
CoffeeScript

_ = require 'underscore-plus'
React = require 'react'
ipc = require 'ipc'
{NamespaceStore, DatabaseStore, Message, ComponentRegistry} = require('inbox-exports')
NewComposeButton = require('./new-compose-button')
ComposerView = require('./composer-view')
module.exports =
item: null # The DOM item the main React component renders into
activate: (@state={}) ->
# Register our composer as the app-wide Composer
ComponentRegistry.register
name: 'Composer'
view: ComposerView
if atom.state.mode is 'editor'
@_activateComposeButton()
else
if @item? then return # Activate once
@item = document.createElement("div")
@item.setAttribute("id", "composer-full-window")
@item.setAttribute("class", "composer-full-window")
document.body.appendChild(@item)
# Wait for the remaining state to be passed into the window
# from our parent. We need to wait for state because the windows are
# preloaded so they open instantly, so we don't have data initially
ipc.on 'composer-state', (optionsJSON) =>
options = JSON.parse(optionsJSON)
@_createDraft(options).then (draftLocalId) =>
React.render(<ComposerView mode="fullwindow" localId={draftLocalId} />, @item)
.catch (error) -> console.error(error)
deactivate: ->
if atom.state.mode is 'composer'
React.unmountComponentAtNode(@item)
@item.remove()
@item = null
else
React.unmountComponentAtNode(@new_compose_button)
@new_compose_button.remove()
@new_compose_button = null
serialize: -> @state
# This logic used to be in the DraftStore (which is where it should be). It
# got moved here becaues of an obscure atom-shell/Chrome bug whereby database
# requests firing right before the new-window loaded would cause the
# new-window to load with about:blank instead of its contents. By moving the
# DB logic here, we can get around this.
_createDraft: ({draftLocalId, draftInitialJSON}) ->
# The NamespaceStore isn't set yet in the new window, populate it first.
NamespaceStore.populateItems().then ->
new Promise (resolve, reject) ->
if draftLocalId?
resolve(draftLocalId)
else
# Create a new draft
draft = new Message
from: [NamespaceStore.current().me()]
date: (new Date)
draft: true
namespaceId: NamespaceStore.current().id
# If initial JSON was provided, apply it to the new model.
# This is used to apply the values in mailto: links to new drafts
if draftInitialJSON
draft.fromJSON(draftInitialJSON)
DatabaseStore.persistModel(draft).then ->
DatabaseStore.localIdForModel(draft).then(resolve).catch(reject)
.catch(reject)
_activateComposeButton: ->
ComponentRegistry.register
view: NewComposeButton
name: 'NewComposeButton'
role: 'Global:Toolbar'