From 2441db654606164ef6303d3c3cbb423bfd997166 Mon Sep 17 00:00:00 2001 From: Halla Moore Date: Fri, 16 Dec 2016 13:07:05 -0800 Subject: [PATCH] fix(draft-store): Don't pop up a draft before it exists in the session Summary: The composer wasn't popping out correctly because the session's draft was still null. This diff switches to using sessionForClientId(), even if the session already exists in _draftSessions, because sessionForClientId() won't create a new session if it doesn't need to, and will always return a promise that resolves once the session gets its draft. This promise will resolve immediately if the session already has a draft. Test Plan: tested locally Reviewers: evan, juan Reviewed By: juan Subscribers: juan, spang Differential Revision: https://phab.nylas.com/D3531 --- src/flux/stores/draft-store.es6 | 35 ++++++++++++--------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/flux/stores/draft-store.es6 b/src/flux/stores/draft-store.es6 index 2b96cff2a..7f73a39cd 100644 --- a/src/flux/stores/draft-store.es6 +++ b/src/flux/stores/draft-store.es6 @@ -289,29 +289,20 @@ class DraftStore extends NylasStore { } NylasEnv.perf.start("Popout Draft"); - let draftJSON = null; - let save = Promise.resolve(); - if (this._draftSessions[draftClientId]) { - save = this._draftSessions[draftClientId].changes.commit().then(() => { - draftJSON = this._draftSessions[draftClientId].draft().toJSON(); - }) - } else { - save = this.sessionForClientId(draftClientId).then((session) => { - draftJSON = session.draft().toJSON(); - }); - } - const title = options.newDraft ? "New Message" : "Message"; - return save.then(() => { - // Since we pass a windowKey, if the popout composer draft already - // exists we'll simply show that one instead of spawning a whole new - // window. - NylasEnv.newWindow({ - title, - hidden: true, // We manually show in ComposerWithWindowProps::onDraftReady - windowKey: `composer-${draftClientId}`, - windowType: "composer-preload", - windowProps: _.extend(options, {draftClientId, draftJSON}), + return this.sessionForClientId(draftClientId).then((session) => { + return session.changes.commit().then(() => { + const draftJSON = session.draft().toJSON(); + // Since we pass a windowKey, if the popout composer draft already + // exists we'll simply show that one instead of spawning a whole new + // window. + NylasEnv.newWindow({ + title, + hidden: true, // We manually show in ComposerWithWindowProps::onDraftReady + windowKey: `composer-${draftClientId}`, + windowType: "composer-preload", + windowProps: _.extend(options, {draftClientId, draftJSON}), + }); }); }); }