fix(file-drop): Wait for attachments before popping composer

This commit is contained in:
Ben Gotow 2016-05-04 19:09:28 -07:00
parent ed27bef1cc
commit 5150dccaf1
3 changed files with 18 additions and 10 deletions

View file

@ -12,6 +12,7 @@
},
"windowTypes": {
"default": true,
"composer": true
"composer": true,
"composer-preload": true
}
}

View file

@ -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]

View file

@ -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()