Update HS / IS URLs when changing server types
parent
344a5d1547
commit
306380d647
|
@ -306,6 +306,28 @@ module.exports = React.createClass({
|
||||||
this.setState({
|
this.setState({
|
||||||
serverType: type,
|
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) {
|
onRegisterClick: function(ev) {
|
||||||
|
|
|
@ -26,16 +26,16 @@ export const FREE = 'Free';
|
||||||
export const PREMIUM = 'Premium';
|
export const PREMIUM = 'Premium';
|
||||||
export const ADVANCED = 'Advanced';
|
export const ADVANCED = 'Advanced';
|
||||||
|
|
||||||
const MATRIX_ORG_HS = 'https://matrix.org';
|
export const TYPES = {
|
||||||
|
FREE: {
|
||||||
const TYPES = [
|
|
||||||
{
|
|
||||||
id: FREE,
|
id: FREE,
|
||||||
label: () => _t('Free'),
|
label: () => _t('Free'),
|
||||||
logo: () => <img src={require('../../../../res/img/feather-icons/matrix-org-bw-logo.svg')} />,
|
logo: () => <img src={require('../../../../res/img/feather-icons/matrix-org-bw-logo.svg')} />,
|
||||||
description: () => _t('Join millions for free on the largest public server'),
|
description: () => _t('Join millions for free on the largest public server'),
|
||||||
|
hsUrl: 'https://matrix.org',
|
||||||
|
isUrl: 'https://vector.im',
|
||||||
},
|
},
|
||||||
{
|
PREMIUM: {
|
||||||
id: PREMIUM,
|
id: PREMIUM,
|
||||||
label: () => _t('Premium'),
|
label: () => _t('Premium'),
|
||||||
logo: () => <img src={require('../../../../res/img/feather-icons/modular-bw-logo.svg')} />,
|
logo: () => <img src={require('../../../../res/img/feather-icons/modular-bw-logo.svg')} />,
|
||||||
|
@ -45,7 +45,7 @@ const TYPES = [
|
||||||
</a>,
|
</a>,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
ADVANCED: {
|
||||||
id: ADVANCED,
|
id: ADVANCED,
|
||||||
label: () => _t('Advanced'),
|
label: () => _t('Advanced'),
|
||||||
logo: () => <div>
|
logo: () => <div>
|
||||||
|
@ -54,12 +54,12 @@ const TYPES = [
|
||||||
</div>,
|
</div>,
|
||||||
description: () => _t('Find other public servers or use a custom server'),
|
description: () => _t('Find other public servers or use a custom server'),
|
||||||
},
|
},
|
||||||
];
|
};
|
||||||
|
|
||||||
function getDefaultType(defaultHsUrl) {
|
function getDefaultType(defaultHsUrl) {
|
||||||
if (!defaultHsUrl) {
|
if (!defaultHsUrl) {
|
||||||
return null;
|
return null;
|
||||||
} else if (defaultHsUrl === MATRIX_ORG_HS) {
|
} else if (defaultHsUrl === TYPES.FREE.hsUrl) {
|
||||||
return FREE;
|
return FREE;
|
||||||
} else if (new URL(defaultHsUrl).hostname.endsWith('.modular.im')) {
|
} else if (new URL(defaultHsUrl).hostname.endsWith('.modular.im')) {
|
||||||
// TODO: Use a Riot config parameter to detect Modular-ness.
|
// TODO: Use a Riot config parameter to detect Modular-ness.
|
||||||
|
@ -81,10 +81,17 @@ export default class ServerTypeSelector extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const { defaultHsUrl } = props;
|
const {
|
||||||
|
defaultHsUrl,
|
||||||
|
onChange,
|
||||||
|
} = props;
|
||||||
|
const type = getDefaultType(defaultHsUrl);
|
||||||
this.state = {
|
this.state = {
|
||||||
selected: getDefaultType(defaultHsUrl),
|
selected: type,
|
||||||
};
|
};
|
||||||
|
if (onChange) {
|
||||||
|
onChange(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSelectedType(type) {
|
updateSelectedType(type) {
|
||||||
|
@ -108,7 +115,8 @@ export default class ServerTypeSelector extends React.PureComponent {
|
||||||
render() {
|
render() {
|
||||||
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
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 { id, label, logo, description } = type;
|
||||||
const classes = classnames(
|
const classes = classnames(
|
||||||
"mx_ServerTypeSelector_type",
|
"mx_ServerTypeSelector_type",
|
||||||
|
@ -118,7 +126,7 @@ export default class ServerTypeSelector extends React.PureComponent {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return <div className={classes} key={id} >
|
serverTypes.push(<div className={classes} key={id} >
|
||||||
<div className="mx_ServerTypeSelector_label">
|
<div className="mx_ServerTypeSelector_label">
|
||||||
{label()}
|
{label()}
|
||||||
</div>
|
</div>
|
||||||
|
@ -130,8 +138,8 @@ export default class ServerTypeSelector extends React.PureComponent {
|
||||||
{description()}
|
{description()}
|
||||||
</div>
|
</div>
|
||||||
</AccessibleButton>
|
</AccessibleButton>
|
||||||
</div>;
|
</div>);
|
||||||
});
|
}
|
||||||
|
|
||||||
return <div className="mx_ServerTypeSelector">
|
return <div className="mx_ServerTypeSelector">
|
||||||
{serverTypes}
|
{serverTypes}
|
||||||
|
|
Loading…
Reference in New Issue