retrieve last used HS/IS URL from local storage, and associated tweaks

This commit is contained in:
Matthew Hodgson 2015-11-10 19:09:24 +00:00
parent 68c1ddd5d2
commit 0825e0a2e2
2 changed files with 52 additions and 29 deletions

View file

@ -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({
<label className="mx_Login_label" htmlFor="advanced">Use custom server options (advanced)</label>
<div style={serverConfigStyle}>
<ServerConfig ref="serverConfig"
defaultHsUrl={this.customHsUrl} defaultIsUrl={this.customIsUrl}
defaultHsUrl={this.state.customHsUrl} defaultIsUrl={this.state.customIsUrl}
onHsUrlChanged={this.onHsUrlChanged}
/>
</div>

View file

@ -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({
<label htmlFor="advanced">Use custom server options (advanced)</label>
<div style={serverConfigStyle}>
<ServerConfig ref="serverConfig"
defaultHsUrl={this.customHsUrl} defaultIsUrl={this.customIsUrl}
defaultHsUrl={this.state.customHsUrl} defaultIsUrl={this.state.customIsUrl}
onHsUrlChanged={this.onServerUrlChanged} onIsUrlChanged={this.onServerUrlChanged} />
</div>
<br />