From 306380d647e4718858fb1e249a68bfe6a572d4e0 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 25 Jan 2019 23:36:18 -0600 Subject: [PATCH] Update HS / IS URLs when changing server types --- src/components/structures/auth/Login.js | 22 ++++++++++++ .../views/auth/ServerTypeSelector.js | 36 +++++++++++-------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/components/structures/auth/Login.js b/src/components/structures/auth/Login.js index b380d431f9..6d61eac895 100644 --- a/src/components/structures/auth/Login.js +++ b/src/components/structures/auth/Login.js @@ -306,6 +306,28 @@ module.exports = React.createClass({ this.setState({ serverType: type, }); + + // When changing server types, set the HS / IS URLs to reasonable defaults for the + // the new type. + switch (type) { + case ServerType.FREE: { + const { hsUrl, isUrl } = ServerType.TYPES.FREE; + this.onServerConfigChange({ + hsUrl, + isUrl, + }); + break; + } + case ServerType.PREMIUM: + // TODO: Handle the Modular case. + break; + case ServerType.ADVANCED: + this.onServerConfigChange({ + hsUrl: this.props.defaultHsUrl, + isUrl: this.props.defaultIsUrl, + }); + break; + } }, onRegisterClick: function(ev) { diff --git a/src/components/views/auth/ServerTypeSelector.js b/src/components/views/auth/ServerTypeSelector.js index 765cc58280..de76e6acf9 100644 --- a/src/components/views/auth/ServerTypeSelector.js +++ b/src/components/views/auth/ServerTypeSelector.js @@ -26,16 +26,16 @@ export const FREE = 'Free'; export const PREMIUM = 'Premium'; export const ADVANCED = 'Advanced'; -const MATRIX_ORG_HS = 'https://matrix.org'; - -const TYPES = [ - { +export const TYPES = { + FREE: { id: FREE, label: () => _t('Free'), logo: () => , description: () => _t('Join millions for free on the largest public server'), + hsUrl: 'https://matrix.org', + isUrl: 'https://vector.im', }, - { + PREMIUM: { id: PREMIUM, label: () => _t('Premium'), logo: () => , @@ -45,7 +45,7 @@ const TYPES = [ , }), }, - { + ADVANCED: { id: ADVANCED, label: () => _t('Advanced'), logo: () =>
@@ -54,12 +54,12 @@ const TYPES = [
, description: () => _t('Find other public servers or use a custom server'), }, -]; +}; function getDefaultType(defaultHsUrl) { if (!defaultHsUrl) { return null; - } else if (defaultHsUrl === MATRIX_ORG_HS) { + } else if (defaultHsUrl === TYPES.FREE.hsUrl) { return FREE; } else if (new URL(defaultHsUrl).hostname.endsWith('.modular.im')) { // TODO: Use a Riot config parameter to detect Modular-ness. @@ -81,10 +81,17 @@ export default class ServerTypeSelector extends React.PureComponent { constructor(props) { super(props); - const { defaultHsUrl } = props; + const { + defaultHsUrl, + onChange, + } = props; + const type = getDefaultType(defaultHsUrl); this.state = { - selected: getDefaultType(defaultHsUrl), + selected: type, }; + if (onChange) { + onChange(type); + } } updateSelectedType(type) { @@ -108,7 +115,8 @@ export default class ServerTypeSelector extends React.PureComponent { render() { const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); - const serverTypes = TYPES.map(type => { + const serverTypes = []; + for (const type of Object.values(TYPES)) { const { id, label, logo, description } = type; const classes = classnames( "mx_ServerTypeSelector_type", @@ -118,7 +126,7 @@ export default class ServerTypeSelector extends React.PureComponent { }, ); - return
+ serverTypes.push(
{label()}
@@ -130,8 +138,8 @@ export default class ServerTypeSelector extends React.PureComponent { {description()}
-
; - }); + ); + } return
{serverTypes}