mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
retrieve last used HS/IS URL from local storage, and associated tweaks
This commit is contained in:
parent
68c1ddd5d2
commit
0825e0a2e2
@ -29,21 +29,28 @@ module.exports = React.createClass({
|
|||||||
displayName: 'Login',
|
displayName: 'Login',
|
||||||
mixins: [LoginController],
|
mixins: [LoginController],
|
||||||
|
|
||||||
getInitialState: function() {
|
|
||||||
return {
|
|
||||||
serverConfigVisible: false
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillMount: function() {
|
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.onHSChosen();
|
||||||
this.customHsUrl = config.default_hs_url;
|
|
||||||
this.customIsUrl = config.default_is_url;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getHsUrl: function() {
|
getHsUrl: function() {
|
||||||
if (this.state.serverConfigVisible) {
|
if (this.state.serverConfigVisible) {
|
||||||
return this.customHsUrl;
|
return this.state.customHsUrl;
|
||||||
} else {
|
} else {
|
||||||
return config.default_hs_url;
|
return config.default_hs_url;
|
||||||
}
|
}
|
||||||
@ -51,7 +58,7 @@ module.exports = React.createClass({
|
|||||||
|
|
||||||
getIsUrl: function() {
|
getIsUrl: function() {
|
||||||
if (this.state.serverConfigVisible) {
|
if (this.state.serverConfigVisible) {
|
||||||
return this.customIsUrl;
|
return this.state.customIsUrl;
|
||||||
} else {
|
} else {
|
||||||
return config.default_is_url;
|
return config.default_is_url;
|
||||||
}
|
}
|
||||||
@ -60,7 +67,7 @@ module.exports = React.createClass({
|
|||||||
onServerConfigVisibleChange: function(ev) {
|
onServerConfigVisibleChange: function(ev) {
|
||||||
this.setState({
|
this.setState({
|
||||||
serverConfigVisible: ev.target.checked
|
serverConfigVisible: ev.target.checked
|
||||||
}, this.onHsUrlChanged);
|
}, this.onHSChosen);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,16 +84,22 @@ module.exports = React.createClass({
|
|||||||
var newHsUrl = this.refs.serverConfig.getHsUrl().trim();
|
var newHsUrl = this.refs.serverConfig.getHsUrl().trim();
|
||||||
var newIsUrl = this.refs.serverConfig.getIsUrl().trim();
|
var newIsUrl = this.refs.serverConfig.getIsUrl().trim();
|
||||||
|
|
||||||
if (newHsUrl == this.customHsUrl &&
|
if (newHsUrl == this.state.customHsUrl &&
|
||||||
newIsUrl == this.customIsUrl)
|
newIsUrl == this.state.customIsUrl)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.customHsUrl = newHsUrl;
|
this.setState({
|
||||||
this.customIsUrl = newIsUrl;
|
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(
|
MatrixClientPeg.replaceUsingUrls(
|
||||||
this.getHsUrl(),
|
this.getHsUrl(),
|
||||||
this.getIsUrl()
|
this.getIsUrl()
|
||||||
@ -95,6 +108,8 @@ module.exports = React.createClass({
|
|||||||
hs_url: this.getHsUrl(),
|
hs_url: this.getHsUrl(),
|
||||||
is_url: this.getIsUrl()
|
is_url: this.getIsUrl()
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
// XXX: HSes do not have to offer password auth, so we
|
// XXX: HSes do not have to offer password auth, so we
|
||||||
// need to update and maybe show a different component
|
// need to update and maybe show a different component
|
||||||
// when a new HS is entered.
|
// 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>
|
<label className="mx_Login_label" htmlFor="advanced">Use custom server options (advanced)</label>
|
||||||
<div style={serverConfigStyle}>
|
<div style={serverConfigStyle}>
|
||||||
<ServerConfig ref="serverConfig"
|
<ServerConfig ref="serverConfig"
|
||||||
defaultHsUrl={this.customHsUrl} defaultIsUrl={this.customIsUrl}
|
defaultHsUrl={this.state.customHsUrl} defaultIsUrl={this.state.customIsUrl}
|
||||||
onHsUrlChanged={this.onHsUrlChanged}
|
onHsUrlChanged={this.onHsUrlChanged}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -29,15 +29,21 @@ module.exports = React.createClass({
|
|||||||
displayName: 'Register',
|
displayName: 'Register',
|
||||||
mixins: [RegisterController],
|
mixins: [RegisterController],
|
||||||
|
|
||||||
getInitialState: function() {
|
|
||||||
return {
|
|
||||||
serverConfigVisible: false
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
this.customHsUrl = config.default_hs_url;
|
// TODO: factor out all localstorage stuff into its own home.
|
||||||
this.customIsUrl = config.default_is_url;
|
// 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() {
|
getRegFormVals: function() {
|
||||||
@ -51,7 +57,7 @@ module.exports = React.createClass({
|
|||||||
|
|
||||||
getHsUrl: function() {
|
getHsUrl: function() {
|
||||||
if (this.state.serverConfigVisible) {
|
if (this.state.serverConfigVisible) {
|
||||||
return this.customHsUrl;
|
return this.state.customHsUrl;
|
||||||
} else {
|
} else {
|
||||||
return config.default_hs_url;
|
return config.default_hs_url;
|
||||||
}
|
}
|
||||||
@ -59,7 +65,7 @@ module.exports = React.createClass({
|
|||||||
|
|
||||||
getIsUrl: function() {
|
getIsUrl: function() {
|
||||||
if (this.state.serverConfigVisible) {
|
if (this.state.serverConfigVisible) {
|
||||||
return this.customIsUrl;
|
return this.state.customIsUrl;
|
||||||
} else {
|
} else {
|
||||||
return config.default_is_url;
|
return config.default_is_url;
|
||||||
}
|
}
|
||||||
@ -72,8 +78,10 @@ module.exports = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onServerUrlChanged: function(newUrl) {
|
onServerUrlChanged: function(newUrl) {
|
||||||
this.customHsUrl = this.refs.serverConfig.getHsUrl();
|
this.setState({
|
||||||
this.customIsUrl = this.refs.serverConfig.getIsUrl();
|
customHsUrl: this.refs.serverConfig.getHsUrl(),
|
||||||
|
customIsUrl: this.refs.serverConfig.getIsUrl(),
|
||||||
|
});
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -99,7 +107,7 @@ module.exports = React.createClass({
|
|||||||
<label htmlFor="advanced">Use custom server options (advanced)</label>
|
<label htmlFor="advanced">Use custom server options (advanced)</label>
|
||||||
<div style={serverConfigStyle}>
|
<div style={serverConfigStyle}>
|
||||||
<ServerConfig ref="serverConfig"
|
<ServerConfig ref="serverConfig"
|
||||||
defaultHsUrl={this.customHsUrl} defaultIsUrl={this.customIsUrl}
|
defaultHsUrl={this.state.customHsUrl} defaultIsUrl={this.state.customIsUrl}
|
||||||
onHsUrlChanged={this.onServerUrlChanged} onIsUrlChanged={this.onServerUrlChanged} />
|
onHsUrlChanged={this.onServerUrlChanged} onIsUrlChanged={this.onServerUrlChanged} />
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
|
Loading…
Reference in New Issue
Block a user