From 541c43482d2c6d6d7c8c3060a4157a3e5a055105 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 13 Feb 2019 10:27:54 -0500 Subject: [PATCH] Make sure to only close import alert after import is done --- src/containers/costume-tab.jsx | 18 +++++++++--------- src/containers/target-pane.jsx | 11 ++++++----- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/containers/costume-tab.jsx b/src/containers/costume-tab.jsx index cff07c68e..7b2713649 100644 --- a/src/containers/costume-tab.jsx +++ b/src/containers/costume-tab.jsx @@ -161,13 +161,12 @@ class CostumeTab extends React.Component { handleNewCostume (costume, fromCostumeLibrary) { const costumes = Array.isArray(costume) ? costume : [costume]; - costumes.forEach(c => { + return Promise.all(costumes.map(c => { if (fromCostumeLibrary) { - this.props.vm.addCostumeFromLibrary(c.md5, c); - } else { - this.props.vm.addCostume(c.md5, c); + return this.props.vm.addCostumeFromLibrary(c.md5, c); } - }); + return this.props.vm.addCostume(c.md5, c); + })); } handleNewBlankCostume () { const name = this.props.vm.editingTarget.isStage ? @@ -211,10 +210,11 @@ class CostumeTab extends React.Component { vmCostumes.forEach((costume, i) => { costume.name = `${fileName}${i ? i + 1 : ''}`; }); - this.handleNewCostume(vmCostumes); - if (fileIndex === fileCount - 1) { - this.props.onCloseAlert('importingAsset'); - } + this.handleNewCostume(vmCostumes).then(() => { + if (fileIndex === fileCount - 1) { + this.props.onCloseAlert('importingAsset'); + } + }); }); }); } diff --git a/src/containers/target-pane.jsx b/src/containers/target-pane.jsx index 5abe145e4..9f4f03e3b 100644 --- a/src/containers/target-pane.jsx +++ b/src/containers/target-pane.jsx @@ -127,7 +127,7 @@ class TargetPane extends React.Component { this.props.onActivateTab(BLOCKS_TAB_INDEX); } handleNewSprite (spriteJSONString) { - this.props.vm.addSprite(spriteJSONString) + return this.props.vm.addSprite(spriteJSONString) .then(this.handleActivateBlocksTab); } handleFileUploadClick () { @@ -138,10 +138,11 @@ class TargetPane extends React.Component { this.props.onShowAlert('importingAsset'); handleFileUpload(e.target, (buffer, fileType, fileName, fileIndex, fileCount) => { spriteUpload(buffer, fileType, fileName, storage, newSprite => { - this.handleNewSprite(newSprite); - if (fileIndex === fileCount - 1) { - this.props.onCloseAlert('importingAsset'); - } + this.handleNewSprite(newSprite).then(() => { + if (fileIndex === fileCount - 1) { + this.props.onCloseAlert('importingAsset'); + } + }); }); }); }