Validate server URLs on blur instead of change
							parent
							
								
									f60cfe5cb2
								
							
						
					
					
						commit
						36d162cb25
					
				|  | @ -571,7 +571,7 @@ module.exports = React.createClass({ | |||
|                     defaultHsUrl={this.props.defaultHsUrl} | ||||
|                     defaultIsUrl={this.props.defaultIsUrl} | ||||
|                     onServerConfigChange={this.onServerConfigChange} | ||||
|                     delayTimeMs={1000} | ||||
|                     delayTimeMs={250} | ||||
|                 />; | ||||
|                 break; | ||||
|             case ServerType.ADVANCED: | ||||
|  | @ -581,7 +581,7 @@ module.exports = React.createClass({ | |||
|                     defaultHsUrl={this.props.defaultHsUrl} | ||||
|                     defaultIsUrl={this.props.defaultIsUrl} | ||||
|                     onServerConfigChange={this.onServerConfigChange} | ||||
|                     delayTimeMs={1000} | ||||
|                     delayTimeMs={250} | ||||
|                 />; | ||||
|                 break; | ||||
|         } | ||||
|  |  | |||
|  | @ -151,6 +151,9 @@ module.exports = React.createClass({ | |||
|     }, | ||||
| 
 | ||||
|     _replaceClient: async function() { | ||||
|         this.setState({ | ||||
|             errorText: null, | ||||
|         }); | ||||
|         this._matrixClient = Matrix.createClient({ | ||||
|             baseUrl: this.state.hsUrl, | ||||
|             idBaseUrl: this.state.isUrl, | ||||
|  | @ -390,7 +393,7 @@ module.exports = React.createClass({ | |||
|                     defaultHsUrl={this.props.defaultHsUrl} | ||||
|                     defaultIsUrl={this.props.defaultIsUrl} | ||||
|                     onServerConfigChange={this.onServerConfigChange} | ||||
|                     delayTimeMs={1000} | ||||
|                     delayTimeMs={250} | ||||
|                 />; | ||||
|                 break; | ||||
|             case ServerType.ADVANCED: | ||||
|  | @ -400,7 +403,7 @@ module.exports = React.createClass({ | |||
|                     defaultHsUrl={this.props.defaultHsUrl} | ||||
|                     defaultIsUrl={this.props.defaultIsUrl} | ||||
|                     onServerConfigChange={this.onServerConfigChange} | ||||
|                     delayTimeMs={1000} | ||||
|                     delayTimeMs={250} | ||||
|                 />; | ||||
|                 break; | ||||
|         } | ||||
|  |  | |||
|  | @ -77,19 +77,22 @@ export default class ModularServerConfig extends React.PureComponent { | |||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     onHomeserverChanged = (ev) => { | ||||
|         this.setState({hsUrl: ev.target.value}, () => { | ||||
|             this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, () => { | ||||
|                 let hsUrl = this.state.hsUrl.trim().replace(/\/$/, ""); | ||||
|                 if (hsUrl === "") hsUrl = this.props.defaultHsUrl; | ||||
|                 this.props.onServerConfigChange({ | ||||
|                     hsUrl: this.state.hsUrl, | ||||
|                     isUrl: this.props.defaultIsUrl, | ||||
|                 }); | ||||
|     onHomeserverBlur = (ev) => { | ||||
|         this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, () => { | ||||
|             let hsUrl = this.state.hsUrl.trim().replace(/\/$/, ""); | ||||
|             if (hsUrl === "") hsUrl = this.props.defaultHsUrl; | ||||
|             this.props.onServerConfigChange({ | ||||
|                 hsUrl: this.state.hsUrl, | ||||
|                 isUrl: this.props.defaultIsUrl, | ||||
|             }); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     onHomeserverChange = (ev) => { | ||||
|         const hsUrl = ev.target.value; | ||||
|         this.setState({ hsUrl }); | ||||
|     } | ||||
| 
 | ||||
|     _waitThenInvoke(existingTimeoutId, fn) { | ||||
|         if (existingTimeoutId) { | ||||
|             clearTimeout(existingTimeoutId); | ||||
|  | @ -117,7 +120,8 @@ export default class ModularServerConfig extends React.PureComponent { | |||
|                         label={_t("Server Name")} | ||||
|                         placeholder={this.props.defaultHsUrl} | ||||
|                         value={this.state.hsUrl} | ||||
|                         onChange={this.onHomeserverChanged} | ||||
|                         onBlur={this.onHomeserverBlur} | ||||
|                         onChange={this.onHomeserverChange} | ||||
|                     /> | ||||
|                 </div> | ||||
|             </div> | ||||
|  |  | |||
|  | @ -76,32 +76,38 @@ export default class ServerConfig extends React.PureComponent { | |||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     onHomeserverChanged = (ev) => { | ||||
|         this.setState({hsUrl: ev.target.value}, () => { | ||||
|             this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, () => { | ||||
|                 let hsUrl = this.state.hsUrl.trim().replace(/\/$/, ""); | ||||
|                 if (hsUrl === "") hsUrl = this.props.defaultHsUrl; | ||||
|                 this.props.onServerConfigChange({ | ||||
|                     hsUrl: this.state.hsUrl, | ||||
|                     isUrl: this.state.isUrl, | ||||
|                 }); | ||||
|     onHomeserverBlur = (ev) => { | ||||
|         this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, () => { | ||||
|             let hsUrl = this.state.hsUrl.trim().replace(/\/$/, ""); | ||||
|             if (hsUrl === "") hsUrl = this.props.defaultHsUrl; | ||||
|             this.props.onServerConfigChange({ | ||||
|                 hsUrl: this.state.hsUrl, | ||||
|                 isUrl: this.state.isUrl, | ||||
|             }); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     onIdentityServerChanged = (ev) => { | ||||
|         this.setState({isUrl: ev.target.value}, () => { | ||||
|             this._isTimeoutId = this._waitThenInvoke(this._isTimeoutId, () => { | ||||
|                 let isUrl = this.state.isUrl.trim().replace(/\/$/, ""); | ||||
|                 if (isUrl === "") isUrl = this.props.defaultIsUrl; | ||||
|                 this.props.onServerConfigChange({ | ||||
|                     hsUrl: this.state.hsUrl, | ||||
|                     isUrl: this.state.isUrl, | ||||
|                 }); | ||||
|     onHomeserverChange = (ev) => { | ||||
|         const hsUrl = ev.target.value; | ||||
|         this.setState({ hsUrl }); | ||||
|     } | ||||
| 
 | ||||
|     onIdentityServerBlur = (ev) => { | ||||
|         this._isTimeoutId = this._waitThenInvoke(this._isTimeoutId, () => { | ||||
|             let isUrl = this.state.isUrl.trim().replace(/\/$/, ""); | ||||
|             if (isUrl === "") isUrl = this.props.defaultIsUrl; | ||||
|             this.props.onServerConfigChange({ | ||||
|                 hsUrl: this.state.hsUrl, | ||||
|                 isUrl: this.state.isUrl, | ||||
|             }); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     onIdentityServerChange = (ev) => { | ||||
|         const isUrl = ev.target.value; | ||||
|         this.setState({ isUrl }); | ||||
|     } | ||||
| 
 | ||||
|     _waitThenInvoke(existingTimeoutId, fn) { | ||||
|         if (existingTimeoutId) { | ||||
|             clearTimeout(existingTimeoutId); | ||||
|  | @ -130,13 +136,15 @@ export default class ServerConfig extends React.PureComponent { | |||
|                         label={_t("Homeserver URL")} | ||||
|                         placeholder={this.props.defaultHsUrl} | ||||
|                         value={this.state.hsUrl} | ||||
|                         onChange={this.onHomeserverChanged} | ||||
|                         onBlur={this.onHomeserverBlur} | ||||
|                         onChange={this.onHomeserverChange} | ||||
|                     /> | ||||
|                     <Field id="mx_ServerConfig_isUrl" | ||||
|                         label={_t("Identity Server URL")} | ||||
|                         placeholder={this.props.defaultIsUrl} | ||||
|                         value={this.state.isUrl} | ||||
|                         onChange={this.onIdentityServerChanged} | ||||
|                         onBlur={this.onIdentityServerBlur} | ||||
|                         onChange={this.onIdentityServerChange} | ||||
|                     /> | ||||
|                 </div> | ||||
|             </div> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 J. Ryan Stinnett
						J. Ryan Stinnett