fix(composer): Show when rendered, send draft JSON to composer windows

This commit is contained in:
Ben Gotow 2016-04-04 18:21:39 -07:00
parent 227f3345a0
commit 0b4127bc4b
7 changed files with 34 additions and 16 deletions

View file

@ -75,8 +75,10 @@ export default ComposedComponent => class extends React.Component {
}
}
// Returns a promise for use in composer/main.es6, to show the window
// once the composer is rendered and focused.
focus() {
Utils.waitFor(() => this.refs.composed).then(() =>
return Utils.waitFor(() => this.refs.composed).then(() =>
this.refs.composed.focus()
).catch(() => {
});

View file

@ -4,6 +4,8 @@ import React from 'react';
import {remote} from 'electron';
import {
Message,
DraftStore,
ComponentRegistry,
WorkspaceStore,
} from 'nylas-exports';
@ -24,13 +26,19 @@ class ComposerWithWindowProps extends React.Component {
componentDidMount() {
if (this.state.draftClientId) {
this.focusComposer();
this.ready();
}
this.unlisten = NylasEnv.onWindowPropsReceived((windowProps) => {
const {errorMessage} = windowProps;
this.setState(windowProps);
this.focusComposer();
const {errorMessage, draftJSON, draftClientId} = windowProps;
if (draftJSON) {
const draft = new Message().fromJSON(draftJSON);
DraftStore._createSession(draftClientId, draft);
}
this.setState({draftClientId});
this.ready();
if (errorMessage) {
this._showInitialErrorDialog(errorMessage);
}
@ -43,8 +51,11 @@ class ComposerWithWindowProps extends React.Component {
}
}
focusComposer = () => {
this.refs.composer.focus();
ready = () => {
this.refs.composer.focus().then(() => {
NylasEnv.getCurrentWindow().show()
NylasEnv.getCurrentWindow().focus()
});
}
render() {

View file

@ -359,6 +359,7 @@ body.platform-win32 {
.button-dropdown {
margin-left: 10px;
padding-top: 11px;
vertical-align: -webkit-baseline-middle;
&:hover {

View file

@ -32,8 +32,8 @@ describe "DatabaseSetupQueryBuilder", ->
'CREATE TABLE IF NOT EXISTS `TestModel` (id TEXT PRIMARY KEY,data BLOB,client_id TEXT,server_id TEXT)',
'CREATE UNIQUE INDEX IF NOT EXISTS `TestModel_id` ON `TestModel` (`id`)',
'CREATE TABLE IF NOT EXISTS `TestModelCategory` (id TEXT KEY, `value` TEXT)'
'CREATE INDEX IF NOT EXISTS `TestModel_Category_id` ON `TestModelCategory` (`id` ASC)'
'CREATE UNIQUE INDEX IF NOT EXISTS `TestModel_Category_val_id` ON `TestModelCategory` (`value` ASC, `id` ASC)',
'CREATE INDEX IF NOT EXISTS `TestModelCategory_id` ON `TestModelCategory` (`id` ASC)'
'CREATE UNIQUE INDEX IF NOT EXISTS `TestModelCategory_val_id` ON `TestModelCategory` (`value` ASC, `id` ASC)',
]
for query,i in queries
expect(query).toBe(expected[i])

View file

@ -50,6 +50,7 @@ describe("DraftStore", () => {
describe("creating and opening drafts", () => {
beforeEach(() => {
const draft = new Message({id: "A", subject: "B", clientId: "A", body: "123"});
this.newDraft = draft;
spyOn(DraftFactory, "createDraftForReply").andReturn(Promise.resolve(draft));
spyOn(DraftFactory, "createOrUpdateDraftForReply").andReturn(Promise.resolve(draft));
spyOn(DraftFactory, "createDraftForForward").andReturn(Promise.resolve(draft));
@ -135,7 +136,7 @@ describe("DraftStore", () => {
expect(NylasEnv.newWindow).toHaveBeenCalledWith({
title: 'Message',
windowType: "composer",
windowProps: { draftClientId: "A" },
windowProps: { draftClientId: "A", draftJSON: this.newDraft.toJSON() },
});
});
});
@ -155,7 +156,7 @@ describe("DraftStore", () => {
expect(NylasEnv.newWindow).toHaveBeenCalledWith({
title: 'Message',
windowType: "composer",
windowProps: { draftClientId: "A" },
windowProps: { draftClientId: "A", draftJSON: this.newDraft.toJSON() },
});
});
});

View file

@ -359,8 +359,6 @@ class WindowManager
if options.bounds
win.browserWindow.setBounds options.bounds
win.showWhenLoaded()
@_replenishHotWindows()
return win

View file

@ -113,7 +113,7 @@ class DraftStore
sessionForClientId: (clientId) =>
if not clientId
throw new Error("DraftStore::sessionForClientId requires a clientId")
@_draftSessions[clientId] ?= new DraftStoreProxy(clientId)
@_draftSessions[clientId] ?= @_createSession(clientId)
@_draftSessions[clientId].prepare()
# Public: Look up the sending state of the given draftClientId.
@ -247,7 +247,7 @@ class DraftStore
# Optimistically create a draft session and hand it the draft so that it
# doesn't need to do a query for it a second from now when the composer wants it.
@_draftSessions[draft.clientId] = new DraftStoreProxy(draft.clientId, draft)
@_createSession(draft.clientId, draft)
DatabaseStore.inTransaction (t) =>
t.persistModel(draft)
@ -258,6 +258,9 @@ class DraftStore
Actions.focusDraft({draftClientId: draft.clientId})
.thenReturn({draftClientId: draft.clientId, draft: draft})
_createSession: (clientId, draft) =>
@_draftSessions[clientId] = new DraftStoreProxy(clientId, draft)
_onPopoutBlankDraft: =>
DraftFactory.createDraft().then (draft) =>
@_finalizeAndPersistNewMessage(draft).then ({draftClientId}) =>
@ -267,9 +270,11 @@ class DraftStore
if not draftClientId?
throw new Error("DraftStore::onPopoutDraftId - You must provide a draftClientId")
draftJSON = null
save = Promise.resolve()
if @_draftSessions[draftClientId]
save = @_draftSessions[draftClientId].changes.commit()
draftJSON = @_draftSessions[draftClientId].draft().toJSON()
title = if options.newDraft then "New Message" else "Message"
@ -283,7 +288,7 @@ class DraftStore
NylasEnv.newWindow
title: title
windowType: "composer"
windowProps: _.extend(options, {draftClientId})
windowProps: _.extend(options, {draftClientId, draftJSON})
_onHandleMailtoLink: (event, urlString) =>
DraftFactory.createDraftForMailto(urlString).then (draft) =>