diff --git a/src/skins/vector/views/templates/Login.js b/src/skins/vector/views/templates/Login.js index 192645dd3c..702043c6c8 100644 --- a/src/skins/vector/views/templates/Login.js +++ b/src/skins/vector/views/templates/Login.js @@ -29,21 +29,28 @@ module.exports = React.createClass({ displayName: 'Login', mixins: [LoginController], - getInitialState: function() { - return { - serverConfigVisible: false - }; - }, - componentWillMount: function() { + // TODO: factor out all localstorage stuff into its own home. + // This is common to Login, Register and MatrixClientPeg + var localStorage = window.localStorage; + if (localStorage) { + var hs_url = localStorage.getItem("mx_hs_url"); + var is_url = localStorage.getItem("mx_is_url"); + } + + this.setState({ + customHsUrl: hs_url || config.default_hs_url, + customIsUrl: is_url || config.default_is_url, + serverConfigVisible: (hs_url !== config.default_hs_url || + is_url !== config.default_is_url) + }); + this.onHSChosen(); - this.customHsUrl = config.default_hs_url; - this.customIsUrl = config.default_is_url; }, getHsUrl: function() { if (this.state.serverConfigVisible) { - return this.customHsUrl; + return this.state.customHsUrl; } else { return config.default_hs_url; } @@ -51,7 +58,7 @@ module.exports = React.createClass({ getIsUrl: function() { if (this.state.serverConfigVisible) { - return this.customIsUrl; + return this.state.customIsUrl; } else { return config.default_is_url; } @@ -60,7 +67,7 @@ module.exports = React.createClass({ onServerConfigVisibleChange: function(ev) { this.setState({ serverConfigVisible: ev.target.checked - }, this.onHsUrlChanged); + }, this.onHSChosen); }, /** @@ -77,16 +84,22 @@ module.exports = React.createClass({ var newHsUrl = this.refs.serverConfig.getHsUrl().trim(); var newIsUrl = this.refs.serverConfig.getIsUrl().trim(); - if (newHsUrl == this.customHsUrl && - newIsUrl == this.customIsUrl) + if (newHsUrl == this.state.customHsUrl && + newIsUrl == this.state.customIsUrl) { return; } else { - this.customHsUrl = newHsUrl; - this.customIsUrl = newIsUrl; + this.setState({ + customHsUrl: newHsUrl, + customIsUrl: newIsUrl, + }); } + // XXX: why are we replacing the MatrixClientPeg here when we're about + // to do it again 1s later in the setTimeout to onHSChosen? -- matthew + // Commenting it out for now to see what breaks. + /* MatrixClientPeg.replaceUsingUrls( this.getHsUrl(), this.getIsUrl() @@ -95,6 +108,8 @@ module.exports = React.createClass({ hs_url: this.getHsUrl(), is_url: this.getIsUrl() }); + */ + // XXX: HSes do not have to offer password auth, so we // need to update and maybe show a different component // when a new HS is entered. @@ -121,7 +136,7 @@ module.exports = React.createClass({