Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Stop integ manager opening on every room switch
Browse files Browse the repository at this point in the history
This was caused by a broken assumption which was AppsDrawer component mounting === clicking on apps draw toggle.

This was introduced in #1312.

Known issue with this fix: deleting the last app doesn't hide the app drawer.
  • Loading branch information
Luke Barnard committed Aug 18, 2017
1 parent 3a7aa92 commit 36fffa1
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/components/views/rooms/AppsDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -65,13 +61,36 @@ module.exports = React.createClass({
// });
});
}

this.dispatcherRef = dis.register(this.onAction.bind(this));
},

componentWillUnmount: function() {
ScalarMessaging.stopListening();
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;
}
},

/**
Expand Down Expand Up @@ -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,
});
Expand All @@ -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') :
Expand All @@ -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) => {
Expand Down

0 comments on commit 36fffa1

Please sign in to comment.