From 36fffa1696d51ed6cb43661f1b69c73781bc3d3a Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 18 Aug 2017 14:48:58 +0100 Subject: [PATCH] Stop integ manager opening on every room switch This was caused by a broken assumption which was AppsDrawer component mounting === clicking on apps draw toggle. This was introduced in matrix-org/matrix-react-sdk#1312. Known issue with this fix: deleting the last app doesn't hide the app drawer. --- src/components/views/rooms/AppsDrawer.js | 44 ++++++++++++++++-------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/components/views/rooms/AppsDrawer.js b/src/components/views/rooms/AppsDrawer.js index b98a18e9e6..42a680bab6 100644 --- a/src/components/views/rooms/AppsDrawer.js +++ b/src/components/views/rooms/AppsDrawer.js @@ -53,10 +53,6 @@ module.exports = React.createClass({ this.scalarClient = new ScalarAuthClient(); this.scalarClient.connect().done(() => { this.forceUpdate(); - if (this.state.apps && this.state.apps.length < 1) { - // XXX: This should not be called here, we should do something much nicer - this.onClickAddWidget(); - } // TODO -- Handle Scalar errors // }, // (err) => { @@ -65,6 +61,8 @@ module.exports = React.createClass({ // }); }); } + + this.dispatcherRef = dis.register(this.onAction.bind(this)); }, componentWillUnmount: function() { @@ -72,6 +70,27 @@ module.exports = React.createClass({ if (MatrixClientPeg.get()) { MatrixClientPeg.get().removeListener("RoomState.events", this.onRoomStateEvents); } + dis.unregister(this.dispatcherRef); + }, + + componentWillReceiveProps(newProps) { + // Room has changed probably, update apps + this._updateApps(); + }, + + 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" + if (action.show) { + const apps = this._getApps(); + if (apps.length === 0) { + this._launchManageIntegrations(); + } + } + break; + } }, /** @@ -139,12 +158,6 @@ module.exports = React.createClass({ _updateApps: function() { const apps = this._getApps(); - if (apps.length < 1) { - dis.dispatch({ - action: 'appsDrawer', - show: false, - }); - } this.setState({ apps: apps, }); @@ -159,11 +172,7 @@ module.exports = React.createClass({ } }, - onClickAddWidget: function(e) { - if (e) { - e.preventDefault(); - } - + _launchManageIntegrations: function() { const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager"); const src = (this.scalarClient !== null && this.scalarClient.hasCredentials()) ? this.scalarClient.getScalarInterfaceUrlForRoom(this.props.room.roomId, 'add_integ') : @@ -173,6 +182,11 @@ module.exports = React.createClass({ }, "mx_IntegrationsManager"); }, + onClickAddWidget: function(e) { + e.preventDefault(); + this._launchManageIntegrations(); + }, + render: function() { const apps = this.state.apps.map( (app, index, arr) => {