From 641cfd058b8fbf9bf914fd358c84b4d5aa7e14e8 Mon Sep 17 00:00:00 2001
From: Ben Wheeler <wheeler.benjamin@gmail.com>
Date: Tue, 16 Oct 2018 10:22:08 -0400
Subject: [PATCH] don't set redux project title directly from sb uploader; only
 extract title from .sb2 and .sb3 filenames

---
 src/components/gui/gui.jsx          |  1 +
 src/containers/sb-file-uploader.jsx | 11 +++--------
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/components/gui/gui.jsx b/src/components/gui/gui.jsx
index 08a74dfca..0ef0801a4 100644
--- a/src/components/gui/gui.jsx
+++ b/src/components/gui/gui.jsx
@@ -368,6 +368,7 @@ GUIComponent.defaultProps = {
     canSave: false,
     canSaveAsCopy: false,
     canShare: false,
+    onUpdateProjectTitle: () => {},
     stageSizeMode: STAGE_SIZE_MODES.large
 };
 
diff --git a/src/containers/sb-file-uploader.jsx b/src/containers/sb-file-uploader.jsx
index 5cffb05ad..0fcf90b02 100644
--- a/src/containers/sb-file-uploader.jsx
+++ b/src/containers/sb-file-uploader.jsx
@@ -6,7 +6,6 @@ import {defineMessages, injectIntl, intlShape} from 'react-intl';
 
 import analytics from '../lib/analytics';
 import log from '../lib/log';
-import {setProjectTitle} from '../reducers/project-title';
 import {LoadingStates, onLoadedProject, onProjectUploadStarted} from '../reducers/project-state';
 
 import {
@@ -79,13 +78,11 @@ class SBFileUploader extends React.Component {
             reader.readAsArrayBuffer(thisFileInput.files[0]);
             // extract the title from the file and set it as current project title
             if (thisFileInput.files[0].name) {
-                const matches = thisFileInput.files[0].name.match(/^(.*?)(\.sb[23]?)?$/);
+                // only parse title from files like "filename.sb2" or "filename.sb3"
+                const matches = thisFileInput.files[0].name.match(/^(.*)\.sb[23]$/);
                 if (matches) {
                     const truncatedProjectTitle = matches[1].substring(0, 100);
-                    this.props.onSetReduxProjectTitle(truncatedProjectTitle);
-                    if (this.props.onUpdateProjectTitle) {
-                        this.props.onUpdateProjectTitle(truncatedProjectTitle);
-                    }
+                    this.props.onUpdateProjectTitle(truncatedProjectTitle);
                 }
             }
         }
@@ -119,7 +116,6 @@ SBFileUploader.propTypes = {
     loadingState: PropTypes.oneOf(LoadingStates),
     onLoadingFinished: PropTypes.func,
     onLoadingStarted: PropTypes.func,
-    onSetReduxProjectTitle: PropTypes.func,
     onUpdateProjectTitle: PropTypes.func,
     vm: PropTypes.shape({
         loadProject: PropTypes.func
@@ -135,7 +131,6 @@ const mapDispatchToProps = dispatch => ({
         dispatch(onLoadedProject(loadingState));
         dispatch(closeLoadingProject());
     },
-    onSetReduxProjectTitle: title => dispatch(setProjectTitle(title)),
     onLoadingStarted: () => {
         dispatch(openLoadingProject());
         dispatch(onProjectUploadStarted());
-- 
GitLab