@@ -15,13 +15,13 @@ limitations under the License.
1515*/
1616
1717import React from 'react' ;
18- import PropTypes from 'prop-types' ;
1918import sdk from '../../../index' ;
2019import { _t } from '../../../languageHandler' ;
2120import { ValidatedServerConfig } from "../../../utils/AutoDiscoveryUtils" ;
2221import SdkConfig from "../../../SdkConfig" ;
2322import AutoDiscoveryUtils from "../../../utils/AutoDiscoveryUtils" ;
2423import * as ServerType from '../../views/auth/ServerTypeSelector' ;
24+ import ServerConfig from "./ServerConfig" ;
2525
2626const MODULAR_URL = 'https://modular.im/?utm_source=riot-web&utm_medium=web&utm_campaign=riot-web-authentication' ;
2727
@@ -33,49 +33,8 @@ const MODULAR_URL = 'https://modular.im/?utm_source=riot-web&utm_medium=web&utm_
3333 * This is a variant of ServerConfig with only the HS field and different body
3434 * text that is specific to the Modular case.
3535 */
36- export default class ModularServerConfig extends React . PureComponent {
37- static propTypes = {
38- onServerConfigChange : PropTypes . func ,
39-
40- // The current configuration that the user is expecting to change.
41- serverConfig : PropTypes . instanceOf ( ValidatedServerConfig ) . isRequired ,
42-
43- delayTimeMs : PropTypes . number , // time to wait before invoking onChanged
44-
45- // Called after the component calls onServerConfigChange
46- onAfterSubmit : PropTypes . func ,
47-
48- // Optional text for the submit button. If falsey, no button will be shown.
49- submitText : PropTypes . string ,
50-
51- // Optional class for the submit button. Only applies if the submit button
52- // is to be rendered.
53- submitClass : PropTypes . string ,
54- } ;
55-
56- static defaultProps = {
57- onServerConfigChange : function ( ) { } ,
58- customHsUrl : "" ,
59- delayTimeMs : 0 ,
60- } ;
61-
62- constructor ( props ) {
63- super ( props ) ;
64-
65- this . state = {
66- busy : false ,
67- errorText : "" ,
68- hsUrl : props . serverConfig . hsUrl ,
69- isUrl : props . serverConfig . isUrl ,
70- } ;
71- }
72-
73- componentWillReceiveProps ( newProps ) {
74- if ( newProps . serverConfig . hsUrl === this . state . hsUrl &&
75- newProps . serverConfig . isUrl === this . state . isUrl ) return ;
76-
77- this . validateAndApplyServer ( newProps . serverConfig . hsUrl , newProps . serverConfig . isUrl ) ;
78- }
36+ export default class ModularServerConfig extends ServerConfig {
37+ static propTypes = ServerConfig . propTypes ;
7938
8039 async validateAndApplyServer ( hsUrl , isUrl ) {
8140 // Always try and use the defaults first
@@ -120,35 +79,6 @@ export default class ModularServerConfig extends React.PureComponent {
12079 return this . validateAndApplyServer ( this . state . hsUrl , ServerType . TYPES . PREMIUM . identityServerUrl ) ;
12180 }
12281
123- onHomeserverBlur = ( ev ) => {
124- this . _hsTimeoutId = this . _waitThenInvoke ( this . _hsTimeoutId , ( ) => {
125- this . validateServer ( ) ;
126- } ) ;
127- } ;
128-
129- onHomeserverChange = ( ev ) => {
130- const hsUrl = ev . target . value ;
131- this . setState ( { hsUrl } ) ;
132- } ;
133-
134- onSubmit = async ( ev ) => {
135- ev . preventDefault ( ) ;
136- ev . stopPropagation ( ) ;
137- const result = await this . validateServer ( ) ;
138- if ( ! result ) return ; // Do not continue.
139-
140- if ( this . props . onAfterSubmit ) {
141- this . props . onAfterSubmit ( ) ;
142- }
143- } ;
144-
145- _waitThenInvoke ( existingTimeoutId , fn ) {
146- if ( existingTimeoutId ) {
147- clearTimeout ( existingTimeoutId ) ;
148- }
149- return setTimeout ( fn . bind ( this ) , this . props . delayTimeMs ) ;
150- }
151-
15282 render ( ) {
15383 const Field = sdk . getComponent ( 'elements.Field' ) ;
15484 const AccessibleButton = sdk . getComponent ( 'elements.AccessibleButton' ) ;
0 commit comments