From 7c2ffc990d2f20b48282166f4acfc1b1ee12d411 Mon Sep 17 00:00:00 2001
From: netpro2k <netpro2k@gmail.com>
Date: Thu, 28 Jun 2018 19:43:14 -0700
Subject: [PATCH] Hide media tools by default unless turned on via query param

---
 src/hub.js                     | 36 ++++++++++++++++++----------------
 src/react-components/2d-hud.js | 25 ++++++++++++++++-------
 2 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/src/hub.js b/src/hub.js
index c68af1595..92fc1fdf8 100644
--- a/src/hub.js
+++ b/src/hub.js
@@ -310,26 +310,28 @@ const onReady = async () => {
       addMedia(e.detail);
     });
 
-    document.addEventListener("paste", e => {
-      if (e.target.nodeName === "INPUT") return;
+    if (qsTruthy("mediaTools")) {
+      document.addEventListener("paste", e => {
+        if (e.target.nodeName === "INPUT") return;
 
-      const imgUrl = e.clipboardData.getData("text");
-      console.log("Pasted: ", imgUrl, e);
-      addMedia(imgUrl);
-    });
+        const imgUrl = e.clipboardData.getData("text");
+        console.log("Pasted: ", imgUrl, e);
+        addMedia(imgUrl);
+      });
 
-    document.addEventListener("dragover", e => {
-      e.preventDefault();
-    });
+      document.addEventListener("dragover", e => {
+        e.preventDefault();
+      });
 
-    document.addEventListener("drop", e => {
-      e.preventDefault();
-      const imgUrl = e.dataTransfer.getData("url");
-      if (imgUrl) {
-        console.log("Droped: ", imgUrl);
-        addMedia(imgUrl);
-      }
-    });
+      document.addEventListener("drop", e => {
+        e.preventDefault();
+        const imgUrl = e.dataTransfer.getData("url");
+        if (imgUrl) {
+          console.log("Droped: ", imgUrl);
+          addMedia(imgUrl);
+        }
+      });
+    }
 
     if (!qsTruthy("offline")) {
       document.body.addEventListener("connected", () => {
diff --git a/src/react-components/2d-hud.js b/src/react-components/2d-hud.js
index 952de6cf8..e32a02d3e 100644
--- a/src/react-components/2d-hud.js
+++ b/src/react-components/2d-hud.js
@@ -1,12 +1,21 @@
 import React from "react";
 import PropTypes from "prop-types";
 import cx from "classnames";
+import queryString from "query-string";
 
 import styles from "../assets/stylesheets/2d-hud.scss";
 
 import FontAwesomeIcon from "@fortawesome/react-fontawesome";
 import faPlus from "@fortawesome/fontawesome-free-solid/faPlus";
 
+const qs = queryString.parse(location.search);
+function qsTruthy(param) {
+  const val = qs[param];
+  // if the param exists but is not set (e.g. "?foo&bar"), its value is null.
+  return val === null || /1|on|true/i.test(val);
+}
+const enableMediaTools = qsTruthy("mediaTools");
+
 const TwoDHUD = ({
   muted,
   frozen,
@@ -36,13 +45,15 @@ const TwoDHUD = ({
         onClick={onToggleSpaceBubble}
       />
     </div>
-    <div
-      className={cx("ui-interactive", styles.iconButton, styles.small, styles.addMediaButton)}
-      title="Add Media"
-      onClick={onClickAddMedia}
-    >
-      <FontAwesomeIcon icon={faPlus} />
-    </div>
+    {enableMediaTools ? (
+      <div
+        className={cx("ui-interactive", styles.iconButton, styles.small, styles.addMediaButton)}
+        title="Add Media"
+        onClick={onClickAddMedia}
+      >
+        <FontAwesomeIcon icon={faPlus} />
+      </div>
+    ) : null}
   </div>
 );
 
-- 
GitLab