From a8a4ca2ed1446fdad54011fddefa420b50c15033 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 10 Jun 2019 15:22:53 +0100 Subject: [PATCH 1/3] Use setBusy interface of js-sdk interactive auth This helps to make sure we only do one auth request at a time. https://github.com/matrix-org/matrix-js-sdk/pull/951 --- src/components/structures/InteractiveAuth.js | 42 ++++++++++---------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/components/structures/InteractiveAuth.js b/src/components/structures/InteractiveAuth.js index 908d7b12bb..6fedfbcfd9 100644 --- a/src/components/structures/InteractiveAuth.js +++ b/src/components/structures/InteractiveAuth.js @@ -23,6 +23,8 @@ import PropTypes from 'prop-types'; import {getEntryComponentForLoginType} from '../views/auth/InteractiveAuthEntryComponents'; +import sdk from '../../index'; + export default React.createClass({ displayName: 'InteractiveAuth', @@ -90,7 +92,8 @@ export default React.createClass({ this._unmounted = false; this._authLogic = new InteractiveAuth({ authData: this.props.authData, - doRequest: this._requestCallback, + doRequest: this.props.makeRequest, + setBusy: this._setBusy, inputs: this.props.inputs, stateUpdated: this._authStateUpdated, matrixClient: this.props.matrixClient, @@ -165,27 +168,19 @@ export default React.createClass({ }); }, - _requestCallback: function(auth, background) { - const makeRequestPromise = this.props.makeRequest(auth); - - // if it's a background request, just do it: we don't want - // it to affect the state of our UI. - if (background) return makeRequestPromise; - - // otherwise, manage the state of the spinner and error messages - this.setState({ - busy: true, - errorText: null, - stageErrorText: null, - }); - return makeRequestPromise.finally(() => { - if (this._unmounted) { - return; - } + _setBusy: function(busy) { + // if we've started doing stuff, reset the error messages + if (busy) { + this.setState({ + busy: true, + errorText: null, + stageErrorText: null, + }); + } else { this.setState({ busy: false, }); - }); + } }, _setFocus: function() { @@ -200,7 +195,14 @@ export default React.createClass({ _renderCurrentStage: function() { const stage = this.state.authStage; - if (!stage) return null; + if (!stage) { + if (this.state.busy) { + const Loader = sdk.getComponent("elements.Spinner"); + return ; + } else { + return null; + } + } const StageComponent = getEntryComponentForLoginType(stage); return ( From cb4af9d04390fe610454af1b5bef6c4a73c683d3 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 10 Jun 2019 16:18:58 +0100 Subject: [PATCH 2/3] Fix test fail --- src/components/structures/InteractiveAuth.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/structures/InteractiveAuth.js b/src/components/structures/InteractiveAuth.js index 6fedfbcfd9..e1722c9745 100644 --- a/src/components/structures/InteractiveAuth.js +++ b/src/components/structures/InteractiveAuth.js @@ -92,7 +92,7 @@ export default React.createClass({ this._unmounted = false; this._authLogic = new InteractiveAuth({ authData: this.props.authData, - doRequest: this.props.makeRequest, + doRequest: this._requestCallback, setBusy: this._setBusy, inputs: this.props.inputs, stateUpdated: this._authStateUpdated, @@ -168,6 +168,13 @@ export default React.createClass({ }); }, + _requestCallback: function(auth) { + // This wrapper just exists because the js-sdk passes a second + // 'busy' param for backwards compat. This throws the tests off + // so discard it here. + return this.props.makeRequest(auth); + }, + _setBusy: function(busy) { // if we've started doing stuff, reset the error messages if (busy) { From db867d1a58b8bd3d871d90c768664c2233f09a48 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 10 Jun 2019 16:27:27 +0100 Subject: [PATCH 3/3] s/setBusy/busyChanged/ --- src/components/structures/InteractiveAuth.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/structures/InteractiveAuth.js b/src/components/structures/InteractiveAuth.js index e1722c9745..ccc906601c 100644 --- a/src/components/structures/InteractiveAuth.js +++ b/src/components/structures/InteractiveAuth.js @@ -93,7 +93,7 @@ export default React.createClass({ this._authLogic = new InteractiveAuth({ authData: this.props.authData, doRequest: this._requestCallback, - setBusy: this._setBusy, + busyChanged: this._onBusyChanged, inputs: this.props.inputs, stateUpdated: this._authStateUpdated, matrixClient: this.props.matrixClient, @@ -175,7 +175,7 @@ export default React.createClass({ return this.props.makeRequest(auth); }, - _setBusy: function(busy) { + _onBusyChanged: function(busy) { // if we've started doing stuff, reset the error messages if (busy) { this.setState({