Merge pull request #3085 from matrix-org/dbkr/one_request_at_a_time_two

Use setBusy interface of js-sdk interactive auth
This commit is contained in:
David Baker 2019-06-11 10:42:27 +01:00 committed by GitHub
commit e1a1492f6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,6 +23,8 @@ import PropTypes from 'prop-types';
import {getEntryComponentForLoginType} from '../views/auth/InteractiveAuthEntryComponents'; import {getEntryComponentForLoginType} from '../views/auth/InteractiveAuthEntryComponents';
import sdk from '../../index';
export default React.createClass({ export default React.createClass({
displayName: 'InteractiveAuth', displayName: 'InteractiveAuth',
@ -91,6 +93,7 @@ export default React.createClass({
this._authLogic = new InteractiveAuth({ this._authLogic = new InteractiveAuth({
authData: this.props.authData, authData: this.props.authData,
doRequest: this._requestCallback, doRequest: this._requestCallback,
busyChanged: this._onBusyChanged,
inputs: this.props.inputs, inputs: this.props.inputs,
stateUpdated: this._authStateUpdated, stateUpdated: this._authStateUpdated,
matrixClient: this.props.matrixClient, matrixClient: this.props.matrixClient,
@ -165,27 +168,26 @@ export default React.createClass({
}); });
}, },
_requestCallback: function(auth, background) { _requestCallback: function(auth) {
const makeRequestPromise = this.props.makeRequest(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);
},
// if it's a background request, just do it: we don't want _onBusyChanged: function(busy) {
// it to affect the state of our UI. // if we've started doing stuff, reset the error messages
if (background) return makeRequestPromise; if (busy) {
// otherwise, manage the state of the spinner and error messages
this.setState({ this.setState({
busy: true, busy: true,
errorText: null, errorText: null,
stageErrorText: null, stageErrorText: null,
}); });
return makeRequestPromise.finally(() => { } else {
if (this._unmounted) {
return;
}
this.setState({ this.setState({
busy: false, busy: false,
}); });
}); }
}, },
_setFocus: function() { _setFocus: function() {
@ -200,7 +202,14 @@ export default React.createClass({
_renderCurrentStage: function() { _renderCurrentStage: function() {
const stage = this.state.authStage; const stage = this.state.authStage;
if (!stage) return null; if (!stage) {
if (this.state.busy) {
const Loader = sdk.getComponent("elements.Spinner");
return <Loader />;
} else {
return null;
}
}
const StageComponent = getEntryComponentForLoginType(stage); const StageComponent = getEntryComponentForLoginType(stage);
return ( return (