From a22e76834336a823a739e4f69c7f2a47a8abd1f6 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Sun, 6 Aug 2017 10:01:48 +0100 Subject: [PATCH] Move room settings button to RoomHeader --- src/components/views/rooms/RoomHeader.js | 83 ++++++++++++++++++++++ src/components/views/rooms/RoomSettings.js | 78 -------------------- 2 files changed, 83 insertions(+), 78 deletions(-) diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index 85aedadf64..d4e390f750 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.js @@ -30,6 +30,9 @@ import linkifyElement from 'linkifyjs/element'; import linkifyMatrix from '../../../linkify-matrix'; import AccessibleButton from '../elements/AccessibleButton'; import {CancelButton} from './SimpleRoomHeader'; +import SdkConfig from '../../../SdkConfig'; +import ScalarAuthClient from '../../../ScalarAuthClient'; +import ScalarMessaging from '../../../ScalarMessaging'; linkifyMatrix(linkify); @@ -57,6 +60,13 @@ module.exports = React.createClass({ }; }, + getInitialState: function() { + return { + scalar_error: null, + showIntegrationsError: false, + }; + }, + componentDidMount: function() { const cli = MatrixClientPeg.get(); cli.on("RoomState.events", this._onRoomStateEvents); @@ -75,7 +85,23 @@ module.exports = React.createClass({ } }, + componentWillMount: function() { + ScalarMessaging.startListening(); + this.scalarClient = null; + if (SdkConfig.get().integrations_ui_url && SdkConfig.get().integrations_rest_url) { + this.scalarClient = new ScalarAuthClient(); + this.scalarClient.connect().done(() => { + this.forceUpdate(); + }, (err) => { + this.setState({ + scalar_error: err, + }); + }); + } + }, + componentWillUnmount: function() { + ScalarMessaging.stopListening(); if (this.props.room) { this.props.room.removeListener("Room.name", this._onRoomNameChange); } @@ -85,6 +111,28 @@ module.exports = React.createClass({ } }, + onManageIntegrations(ev) { + ev.preventDefault(); + const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager"); + Modal.createDialog(IntegrationsManager, { + src: (this.scalarClient !== null && this.scalarClient.hasCredentials()) ? + this.scalarClient.getScalarInterfaceUrlForRoom(this.props.room.roomId) : + null, + onFinished: ()=>{ + if (this._calcSavePromises().length === 0) { + this.props.onCancelClick(ev); + } + }, + }, "mx_IntegrationsManager"); + }, + + onShowIntegrationsError(ev) { + ev.preventDefault(); + this.setState({ + showIntegrationsError: !this.state.showIntegrationsError, + }); + }, + _onRoomStateEvents: function(event, state) { if (!this.props.room || event.getRoomId() !== this.props.room.roomId) { return; @@ -320,10 +368,45 @@ module.exports = React.createClass({ } let rightRow; + let integrationsButton; + let integrationsError; + if (this.scalarClient !== null) { + if (this.state.showIntegrationsError && this.state.scalar_error) { + console.error(this.state.scalar_error); + integrationsError = ( + + { _t('Could not connect to the integration server') } + + ); + } + + if (this.scalarClient.hasCredentials()) { + integrationsButton = ( + + + + ); + } else if (this.state.scalar_error) { + integrationsButton = ( +
+ + { integrationsError } +
+ ); + } else { + integrationsButton = ( + + + + ); + } + } + if (!this.props.editing) { rightRow =
{ settingsButton } + { integrationsButton } { forgetButton } { searchButton } { rightPanelButtons } diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index d6a973f648..1baaf3aaa9 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -24,8 +24,6 @@ import sdk from '../../../index'; import Modal from '../../../Modal'; import ObjectUtils from '../../../ObjectUtils'; import dis from '../../../dispatcher'; -import ScalarAuthClient from '../../../ScalarAuthClient'; -import ScalarMessaging from '../../../ScalarMessaging'; import UserSettingsStore from '../../../UserSettingsStore'; import AccessibleButton from '../elements/AccessibleButton'; @@ -118,14 +116,10 @@ module.exports = React.createClass({ // Default to false if it's undefined, otherwise react complains about changing // components from uncontrolled to controlled isRoomPublished: this._originalIsRoomPublished || false, - scalar_error: null, - showIntegrationsError: false, }; }, componentWillMount: function() { - ScalarMessaging.startListening(); - MatrixClientPeg.get().on("RoomMember.membership", this._onRoomMemberMembership); MatrixClientPeg.get().getRoomDirectoryVisibility( @@ -137,18 +131,6 @@ module.exports = React.createClass({ console.error("Failed to get room visibility: " + err); }); - this.scalarClient = null; - if (SdkConfig.get().integrations_ui_url && SdkConfig.get().integrations_rest_url) { - this.scalarClient = new ScalarAuthClient(); - this.scalarClient.connect().done(() => { - this.forceUpdate(); - }, (err) => { - this.setState({ - scalar_error: err - }); - }); - } - dis.dispatch({ action: 'ui_opacity', sideOpacity: 0.3, @@ -157,8 +139,6 @@ module.exports = React.createClass({ }, componentWillUnmount: function() { - ScalarMessaging.stopListening(); - const cli = MatrixClientPeg.get(); if (cli) { cli.removeListener("RoomMember.membership", this._onRoomMemberMembership); @@ -513,28 +493,6 @@ module.exports = React.createClass({ roomState.mayClientSendStateEvent("m.room.guest_access", cli)); }, - onManageIntegrations(ev) { - ev.preventDefault(); - var IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager"); - Modal.createDialog(IntegrationsManager, { - src: (this.scalarClient !== null && this.scalarClient.hasCredentials()) ? - this.scalarClient.getScalarInterfaceUrlForRoom(this.props.room.roomId) : - null, - onFinished: ()=>{ - if (this._calcSavePromises().length === 0) { - this.props.onCancelClick(ev); - } - }, - }, "mx_IntegrationsManager"); - }, - - onShowIntegrationsError(ev) { - ev.preventDefault(); - this.setState({ - showIntegrationsError: !this.state.showIntegrationsError, - }); - }, - onLeaveClick() { dis.dispatch({ action: 'leave_room', @@ -796,46 +754,10 @@ module.exports = React.createClass({
; } - let integrationsButton; - let integrationsError; - - if (this.scalarClient !== null) { - if (this.state.showIntegrationsError && this.state.scalar_error) { - console.error(this.state.scalar_error); - integrationsError = ( - - { _t('Could not connect to the integration server') } - - ); - } - - if (this.scalarClient.hasCredentials()) { - integrationsButton = ( -
- { _t('Manage Integrations') } -
- ); - } else if (this.state.scalar_error) { - integrationsButton = ( -
- Integrations Error - { integrationsError } -
- ); - } else { - integrationsButton = ( -
- { _t('Manage Integrations') } -
- ); - } - } - return (
{ leaveButton } - { integrationsButton } { tagsSection }