From 0825e0a2e275b2395509a7053526ef265d7bb462 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Tue, 10 Nov 2015 19:09:24 +0000 Subject: [PATCH] retrieve last used HS/IS URL from local storage, and associated tweaks --- src/skins/vector/views/templates/Login.js | 47 +++++++++++++------- src/skins/vector/views/templates/Register.js | 34 ++++++++------ 2 files changed, 52 insertions(+), 29 deletions(-) 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({
diff --git a/src/skins/vector/views/templates/Register.js b/src/skins/vector/views/templates/Register.js index f3c81737a2..28ae9ffc63 100644 --- a/src/skins/vector/views/templates/Register.js +++ b/src/skins/vector/views/templates/Register.js @@ -29,15 +29,21 @@ module.exports = React.createClass({ displayName: 'Register', mixins: [RegisterController], - getInitialState: function() { - return { - serverConfigVisible: false - }; - }, - componentWillMount: function() { - this.customHsUrl = config.default_hs_url; - this.customIsUrl = config.default_is_url; + // 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) + }); }, getRegFormVals: function() { @@ -51,7 +57,7 @@ module.exports = React.createClass({ getHsUrl: function() { if (this.state.serverConfigVisible) { - return this.customHsUrl; + return this.state.customHsUrl; } else { return config.default_hs_url; } @@ -59,7 +65,7 @@ module.exports = React.createClass({ getIsUrl: function() { if (this.state.serverConfigVisible) { - return this.customIsUrl; + return this.state.customIsUrl; } else { return config.default_is_url; } @@ -72,8 +78,10 @@ module.exports = React.createClass({ }, onServerUrlChanged: function(newUrl) { - this.customHsUrl = this.refs.serverConfig.getHsUrl(); - this.customIsUrl = this.refs.serverConfig.getIsUrl(); + this.setState({ + customHsUrl: this.refs.serverConfig.getHsUrl(), + customIsUrl: this.refs.serverConfig.getIsUrl(), + }); this.forceUpdate(); }, @@ -99,7 +107,7 @@ module.exports = React.createClass({