From bb9f63ce6736672d28ba38112cd042fe02b9a520 Mon Sep 17 00:00:00 2001
From: Karishma Chadha <kchadha@scratch.mit.edu>
Date: Mon, 9 Apr 2018 15:02:53 -0400
Subject: [PATCH] Fixes for load button issues.

---
 src/containers/load-button.jsx | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/containers/load-button.jsx b/src/containers/load-button.jsx
index e52a6735d..9364728a4 100644
--- a/src/containers/load-button.jsx
+++ b/src/containers/load-button.jsx
@@ -24,18 +24,24 @@ class LoadButton extends React.Component {
         };
     }
     handleChange (e) {
-        this.props.openLoadingState();
         // Remove the hash if any (without triggering a hash change event or a reload)
         history.replaceState({}, document.title, '.');
         const reader = new FileReader();
+        const thisFileInput = e.target;
         reader.onload = () => this.props.vm.loadProject(reader.result)
             .then(() => {
                 this.props.closeLoadingState();
+                // Reset the file input after project is loaded
+                // This is necessary in case the user wants to reload a project
+                thisFileInput.value = null;
             })
             .catch(error => {
                 this.setState({loadingError: true, errorMessage: error});
             });
-        reader.readAsArrayBuffer(e.target.files[0]);
+        if (thisFileInput.files) { // Don't attempt to load if no file was selected
+            this.props.openLoadingState();
+            reader.readAsArrayBuffer(thisFileInput.files[0]);
+        }
     }
     handleClick () {
         this.fileInput.click();
-- 
GitLab