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.
This commit is contained in:
Luke Barnard 2017-08-18 14:48:58 +01:00
parent 3a7aa926c3
commit 36fffa1696

View file

@ -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) => {