Factor out div ID name to avoid tight coupling with logic class.

This commit is contained in:
Kegan Dougal 2015-11-19 16:08:25 +00:00
parent 3cf9f786aa
commit bb6eeea0d8
2 changed files with 9 additions and 5 deletions

View file

@ -19,6 +19,8 @@ limitations under the License.
var React = require('react'); var React = require('react');
var sdk = require('matrix-react-sdk') var sdk = require('matrix-react-sdk')
var DIV_ID = 'mx_recaptcha';
/** /**
* A pure UI component which displays a captcha form. * A pure UI component which displays a captcha form.
*/ */
@ -26,7 +28,7 @@ module.exports = React.createClass({
displayName: 'CaptchaForm', displayName: 'CaptchaForm',
propTypes: { propTypes: {
onCaptchaLoaded: React.PropTypes.func.isRequired onCaptchaLoaded: React.PropTypes.func.isRequired // called with div id name
}, },
getDefaultProps: function() { getDefaultProps: function() {
@ -46,7 +48,7 @@ module.exports = React.createClass({
var scriptTag = document.createElement('script'); var scriptTag = document.createElement('script');
window.mx_on_recaptcha_loaded = function() { window.mx_on_recaptcha_loaded = function() {
console.log("Loaded recaptcha script."); console.log("Loaded recaptcha script.");
self.props.onCaptchaLoaded(); self.props.onCaptchaLoaded(DIV_ID);
}; };
scriptTag.setAttribute( scriptTag.setAttribute(
'src', global.location.protocol+"//www.google.com/recaptcha/api.js?onload=mx_on_recaptcha_loaded&render=explicit" 'src', global.location.protocol+"//www.google.com/recaptcha/api.js?onload=mx_on_recaptcha_loaded&render=explicit"
@ -60,7 +62,7 @@ module.exports = React.createClass({
return ( return (
<div ref="recaptchaContainer"> <div ref="recaptchaContainer">
This Home Server would like to make sure you are not a robot This Home Server would like to make sure you are not a robot
<div id="mx_recaptcha"></div> <div id={DIV_ID}></div>
</div> </div>
); );
} }

View file

@ -154,8 +154,10 @@ module.exports = React.createClass({
}); });
}, },
onCaptchaLoaded: function() { onCaptchaLoaded: function(divIdName) {
this.registerLogic.tellStage("m.login.recaptcha", "loaded"); this.registerLogic.tellStage("m.login.recaptcha", {
divId: divIdName
});
}, },
// TODO: // TODO: