From fd28ad8e0ca2210c519eca1116743c18439055dc Mon Sep 17 00:00:00 2001
From: Greg Fodor <gfodor@gmail.com>
Date: Fri, 20 Jul 2018 20:54:33 +0000
Subject: [PATCH] Allow specification of initial environment

---
 src/index.js                             |  5 ++++-
 src/react-components/home-root.js        | 10 ++++++++--
 src/react-components/hub-create-panel.js | 13 +++++++++++--
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/index.js b/src/index.js
index 32558cd4e..d0b5c4557 100644
--- a/src/index.js
+++ b/src/index.js
@@ -10,6 +10,9 @@ const qs = queryString.parse(location.search);
 registerTelemetry();
 
 ReactDOM.render(
-  <HomeRoot dialogType={qs.list_signup ? InfoDialog.dialogTypes.updates : null} />,
+  <HomeRoot
+    initialEnvironment={qs.initial_environment}
+    dialogType={qs.list_signup ? InfoDialog.dialogTypes.updates : null}
+  />,
   document.getElementById("home-root")
 );
diff --git a/src/react-components/home-root.js b/src/react-components/home-root.js
index 318fc88d9..d27bc310d 100644
--- a/src/react-components/home-root.js
+++ b/src/react-components/home-root.js
@@ -17,7 +17,8 @@ addLocaleData([...en]);
 class HomeRoot extends Component {
   static propTypes = {
     intl: PropTypes.object,
-    dialogType: PropTypes.symbol
+    dialogType: PropTypes.symbol,
+    initialEnvironment: PropTypes.string
   };
 
   state = {
@@ -155,7 +156,12 @@ class HomeRoot extends Component {
                 </div>
               </div>
               <div className="hero-content__create">
-                {this.state.environments.length > 0 && <HubCreatePanel environments={this.state.environments} />}
+                {this.state.environments.length > 0 && (
+                  <HubCreatePanel
+                    initialEnvironment={this.props.initialEnvironment}
+                    environments={this.state.environments}
+                  />
+                )}
               </div>
             </div>
             <div className="footer-content">
diff --git a/src/react-components/hub-create-panel.js b/src/react-components/hub-create-panel.js
index dc10b99ac..959a4a933 100644
--- a/src/react-components/hub-create-panel.js
+++ b/src/react-components/hub-create-panel.js
@@ -15,16 +15,25 @@ const HUB_NAME_PATTERN = "^[A-Za-z0-9-'\":!@#$%^&*(),.?~ ]{4,64}$";
 class HubCreatePanel extends Component {
   static propTypes = {
     intl: PropTypes.object,
-    environments: PropTypes.array
+    environments: PropTypes.array,
+    initialEnvironment: PropTypes.string
   };
 
   constructor(props) {
     super(props);
 
+    let environmentIndex = Math.floor(Math.random() * props.environments.length);
+
+    if (props.initialEnvironment) {
+      environmentIndex = props.environments.findIndex(
+        e => e.name.toLowerCase() === props.initialEnvironment.toLowerCase()
+      );
+    }
+
     this.state = {
       ready: false,
       name: generateHubName(),
-      environmentIndex: Math.floor(Math.random() * props.environments.length),
+      environmentIndex,
       // HACK: expand on small screens by default to ensure scene selection possible.
       // Eventually this could/should be done via media queries.
       expanded: window.innerWidth < 420
-- 
GitLab