From 8f78da4e11c66bfb0196213e5bddfd22fa3a8ac1 Mon Sep 17 00:00:00 2001 From: nthouliss Date: Mon, 11 Apr 2022 15:55:20 +1000 Subject: [PATCH] Remove map states of corrupted maps on import --- src/modals/ImportExportModal.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/modals/ImportExportModal.tsx b/src/modals/ImportExportModal.tsx index 3b0ce6e..b57be21 100644 --- a/src/modals/ImportExportModal.tsx +++ b/src/modals/ImportExportModal.tsx @@ -325,24 +325,39 @@ function ImportExportModal({ } } + // compare items added to newAssetIds against those that were processed const unprocessedAssets = Object.keys(newAssetIds).filter(item => processedAssetIds.indexOf(item) < 0); let unprocessedMaps = 0 let unprocessedTokens = 0 + // check if there are any items that have been unprocessed if (unprocessedAssets.length > 0) { const unprocessedItems: { id: string, name: string }[] = [] for (let item of unprocessedAssets) { + // get information of unprocessed item from oldAssetIds list let unprocessedItem = oldAssetIds[item] + // should only remove corrupted asset once (one map can have multiple unprocessed assets) if (!!!(unprocessedItems.some(value => value.id === unprocessedItem.itemId))) { unprocessedItems.push({ id: unprocessedItem.itemId, name: unprocessedItem.itemName }) if (unprocessedItem.item === "map") { unprocessedMaps += 1 + + // remove corrupt map from newMaps list -> otherwise corrupt data will be imported const index = newMaps.findIndex(map => map.id === unprocessedItem.newId) - newMaps.splice(index, 1) + if (index !== -1) { + newMaps.splice(index, 1) + } + + const stateIndex = newStates.findIndex(state => state.mapId === unprocessedItem.newId) + if (stateIndex !== -1) { + newStates.splice(stateIndex, 1) + } } else if (unprocessedItem.item === "token") { unprocessedTokens += 1 const index = newTokens.findIndex(token => token.id === unprocessedItem.newId) - newTokens.splice(index, 1) + if (index !== -1) { + newTokens.splice(index, 1) + } } } }