From 33f34fb54f88ee769a424cf39e58b28cb65f71b5 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Thu, 15 Apr 2021 16:28:39 +1000 Subject: [PATCH] Fix file import button --- src/modals/SelectMapModal.js | 16 +++++++++++----- src/modals/SelectTokensModal.js | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/modals/SelectMapModal.js b/src/modals/SelectMapModal.js index bfcc3f1..517bc45 100644 --- a/src/modals/SelectMapModal.js +++ b/src/modals/SelectMapModal.js @@ -120,11 +120,6 @@ function SelectMapModal({ await navigator.storage.persist(); } - // Set file input to null to allow adding the same image 2 times in a row - if (fileInputRef.current) { - fileInputRef.current.value = null; - } - let mapFiles = []; for (let file of files) { if (file.size > 5e7) { @@ -144,11 +139,21 @@ function SelectMapModal({ for (let file of mapFiles) { await handleImageUpload(file); } + + clearFileInput(); + } + + function clearFileInput() { + // Set file input to null to allow adding the same image 2 times in a row + if (fileInputRef.current) { + fileInputRef.current.value = null; + } } function handleLargeImageWarningCancel() { largeImageWarningFiles.current = undefined; setShowLargeImageWarning(false); + clearFileInput(); } async function handleLargeImageWarningConfirm() { @@ -158,6 +163,7 @@ function SelectMapModal({ await handleImageUpload(file); } largeImageWarningFiles.current = undefined; + clearFileInput(); } async function handleImageUpload(file) { diff --git a/src/modals/SelectTokensModal.js b/src/modals/SelectTokensModal.js index 1a640cc..91789c5 100644 --- a/src/modals/SelectTokensModal.js +++ b/src/modals/SelectTokensModal.js @@ -90,11 +90,6 @@ function SelectTokensModal({ isOpen, onRequestClose }) { await navigator.storage.persist(); } - // Set file input to null to allow adding the same image 2 times in a row - if (fileInputRef.current) { - fileInputRef.current.value = null; - } - let tokenFiles = []; for (let file of files) { if (file.size > 5e7) { @@ -114,11 +109,21 @@ function SelectTokensModal({ isOpen, onRequestClose }) { for (let file of tokenFiles) { await handleImageUpload(file); } + + clearFileInput(); + } + + function clearFileInput() { + // Set file input to null to allow adding the same image 2 times in a row + if (fileInputRef.current) { + fileInputRef.current.value = null; + } } function handleLargeImageWarningCancel() { largeImageWarningFiles.current = undefined; setShowLargeImageWarning(false); + clearFileInput(); } async function handleLargeImageWarningConfirm() { @@ -128,6 +133,7 @@ function SelectTokensModal({ isOpen, onRequestClose }) { await handleImageUpload(file); } largeImageWarningFiles.current = undefined; + clearFileInput(); } async function handleImageUpload(file) {