From 5150dccaf1addc193fac8edb6a9bc31596d24742 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 4 May 2016 19:09:28 -0700 Subject: [PATCH] fix(file-drop): Wait for attachments before popping composer --- internal_packages/attachments/package.json | 3 ++- src/flux/stores/draft-store.coffee | 14 ++++++++++++-- src/flux/stores/file-upload-store.coffee | 11 ++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/internal_packages/attachments/package.json b/internal_packages/attachments/package.json index 0fdbb2072..42c35c833 100644 --- a/internal_packages/attachments/package.json +++ b/internal_packages/attachments/package.json @@ -12,6 +12,7 @@ }, "windowTypes": { "default": true, - "composer": true + "composer": true, + "composer-preload": true } } diff --git a/src/flux/stores/draft-store.coffee b/src/flux/stores/draft-store.coffee index a27ee6379..fc8ef1ccc 100644 --- a/src/flux/stores/draft-store.coffee +++ b/src/flux/stores/draft-store.coffee @@ -299,10 +299,20 @@ class DraftStore _onHandleMailFiles: (event, paths) => DraftFactory.createDraft().then (draft) => - @_finalizeAndPersistNewMessage(draft, popout: true) + @_finalizeAndPersistNewMessage(draft) .then ({draftClientId}) => + remaining = paths.length + callback = => + remaining -= 1 + if remaining is 0 + @_onPopoutDraftClientId(draftClientId) + for path in paths - Actions.addAttachment({filePath: path, messageClientId: draftClientId}) + Actions.addAttachment({ + filePath: path, + messageClientId: draftClientId, + callback: callback + }) _onDestroyDraft: (draftClientId) => session = @_draftSessions[draftClientId] diff --git a/src/flux/stores/file-upload-store.coffee b/src/flux/stores/file-upload-store.coffee index e21474dd8..dc0d6bab0 100644 --- a/src/flux/stores/file-upload-store.coffee +++ b/src/flux/stores/file-upload-store.coffee @@ -59,7 +59,9 @@ class FileUploadStore extends NylasStore pathsToOpen.forEach (filePath) -> Actions.addAttachment({messageClientId, filePath}) - _onAddAttachment: ({messageClientId, filePath}) -> + _onAddAttachment: ({messageClientId, filePath, callback}) -> + callback ?= -> + @_verifyId(messageClientId) @_getFileStats({messageClientId, filePath}) .then(@_makeUpload) @@ -69,6 +71,7 @@ class FileUploadStore extends NylasStore .then (upload) => @_applySessionChanges upload.messageClientId, (uploads) -> uploads.concat([upload]) + .then(callback) .catch(@_onAttachFileError) _onRemoveAttachment: (upload) -> @@ -145,10 +148,4 @@ class FileUploadStore extends NylasStore uploads = changeFunction(session.draft().uploads) session.changes.add({uploads}) - # In some scenarios (like dropping attachments on the dock icon), files - # are added to drafts which may be open in another composer window. - # Committing here ensures the files appear immediately, no matter where the - # user is now viewing the draft. - session.changes.commit() - module.exports = new FileUploadStore()