From f032284eff219c279939740d65216cb49e50dfa8 Mon Sep 17 00:00:00 2001 From: "Andrew (anoa)" Date: Tue, 24 Oct 2017 16:21:46 -0700 Subject: [PATCH 1/3] Remember whether widget drawer was hidden per-room Fixes #4850 Signed-off-by: Andrew (anoa) --- src/components/structures/RoomView.js | 16 +++++++++++++++- src/components/views/rooms/AppsDrawer.js | 15 +++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 83ca987276..583ce78785 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -281,7 +281,7 @@ module.exports = React.createClass({ this.setState({ isPeeking: false, }); - + // This won't necessarily be a MatrixError, but we duck-type // here and say if it's got an 'errcode' key with the right value, // it means we can't peek. @@ -305,6 +305,20 @@ module.exports = React.createClass({ _shouldShowApps: function(room) { if (!BROWSER_SUPPORTS_SANDBOX) return false; + // Check if user has prompted to close this app before + // If so, do not show apps + let showWidget = localStorage.getItem( + room.roomId + "_show_widget_drawer"); + + console.warn(room); + console.warn("Key is: " + room.roomId + "_show_widget_drawer"); + console.warn("showWidget is: " + showWidget); + + if (showWidget == "false") { + console.warn("We're blocking the widget from loading."); + return false; + } + const appsStateEvents = room.currentState.getStateEvents('im.vector.modular.widgets'); // any valid widget = show apps for (let i = 0; i < appsStateEvents.length; i++) { diff --git a/src/components/views/rooms/AppsDrawer.js b/src/components/views/rooms/AppsDrawer.js index 1c9296228d..9bc946bc4b 100644 --- a/src/components/views/rooms/AppsDrawer.js +++ b/src/components/views/rooms/AppsDrawer.js @@ -83,14 +83,25 @@ module.exports = React.createClass({ onAction: function(action) { switch (action.action) { case 'appsDrawer': - // When opening the app draw when there aren't any apps, auto-launch the - // integrations manager to skip the awkward click on "Add widget" + // When opening the app drawer when there aren't any apps, + // auto-launch the integrations manager to skip the awkward + // click on "Add widget" + let widgetStateKey = this.props.room.roomId + "_show_widget_drawer"; if (action.show) { const apps = this._getApps(); if (apps.length === 0) { this._launchManageIntegrations(); } + + localStorage.removeItem(widgetStateKey); + } else { + // Store hidden state of widget + // Don't show if previously hidden + console.warn("Storing hidden widget state for room - ", + this.props.room.roomId); + localStorage.setItem(widgetStateKey, false); } + break; } }, From 9821f0d459766dc2e1a3436c0978371981b3e42b Mon Sep 17 00:00:00 2001 From: "Andrew (anoa)" Date: Tue, 24 Oct 2017 16:37:23 -0700 Subject: [PATCH 2/3] Fix linting Signed-off-by: Andrew (anoa) --- src/components/views/rooms/AppsDrawer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/AppsDrawer.js b/src/components/views/rooms/AppsDrawer.js index 9bc946bc4b..09bf4e616b 100644 --- a/src/components/views/rooms/AppsDrawer.js +++ b/src/components/views/rooms/AppsDrawer.js @@ -81,12 +81,12 @@ module.exports = React.createClass({ }, onAction: function(action) { + const widgetStateKey = this.props.room.roomId + "_show_widget_drawer"; switch (action.action) { case 'appsDrawer': // When opening the app drawer when there aren't any apps, // auto-launch the integrations manager to skip the awkward // click on "Add widget" - let widgetStateKey = this.props.room.roomId + "_show_widget_drawer"; if (action.show) { const apps = this._getApps(); if (apps.length === 0) { From b4868a6846461918836f91b3b1364ad6c690785a Mon Sep 17 00:00:00 2001 From: "Andrew (anoa)" Date: Thu, 26 Oct 2017 11:17:13 -0700 Subject: [PATCH 3/3] showWidget->hideWidgetDrawer and remove logs Signed-off-by: Andrew (anoa) --- src/components/structures/RoomView.js | 15 +++++---------- src/components/views/rooms/AppsDrawer.js | 8 +++----- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 583ce78785..38603f1805 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -305,17 +305,12 @@ module.exports = React.createClass({ _shouldShowApps: function(room) { if (!BROWSER_SUPPORTS_SANDBOX) return false; - // Check if user has prompted to close this app before - // If so, do not show apps - let showWidget = localStorage.getItem( - room.roomId + "_show_widget_drawer"); + // Check if user has previously chosen to hide the app drawer for this + // room. If so, do not show apps + let hideWidgetDrawer = localStorage.getItem( + room.roomId + "_hide_widget_drawer"); - console.warn(room); - console.warn("Key is: " + room.roomId + "_show_widget_drawer"); - console.warn("showWidget is: " + showWidget); - - if (showWidget == "false") { - console.warn("We're blocking the widget from loading."); + if (hideWidgetDrawer === "true") { return false; } diff --git a/src/components/views/rooms/AppsDrawer.js b/src/components/views/rooms/AppsDrawer.js index 09bf4e616b..9a3ba5f329 100644 --- a/src/components/views/rooms/AppsDrawer.js +++ b/src/components/views/rooms/AppsDrawer.js @@ -81,7 +81,7 @@ module.exports = React.createClass({ }, onAction: function(action) { - const widgetStateKey = this.props.room.roomId + "_show_widget_drawer"; + const hideWidgetKey = this.props.room.roomId + "_hide_widget_drawer"; switch (action.action) { case 'appsDrawer': // When opening the app drawer when there aren't any apps, @@ -93,13 +93,11 @@ module.exports = React.createClass({ this._launchManageIntegrations(); } - localStorage.removeItem(widgetStateKey); + localStorage.removeItem(hideWidgetKey); } else { // Store hidden state of widget // Don't show if previously hidden - console.warn("Storing hidden widget state for room - ", - this.props.room.roomId); - localStorage.setItem(widgetStateKey, false); + localStorage.setItem(hideWidgetKey, true); } break;