Make sure captcha disappears when container does

Should fix https://github.com/vector-im/riot-web/issues/4095
This commit is contained in:
David Baker 2017-06-16 10:25:51 +01:00
parent 56eb71d19f
commit 2a01e638b7

View file

@ -46,6 +46,10 @@ module.exports = React.createClass({
}; };
}, },
componentWillMount: function() {
this._captchaWidgetId = null;
},
componentDidMount: function() { componentDidMount: function() {
// Just putting a script tag into the returned jsx doesn't work, annoyingly, // Just putting a script tag into the returned jsx doesn't work, annoyingly,
// so we do this instead. // so we do this instead.
@ -75,6 +79,10 @@ module.exports = React.createClass({
} }
}, },
componentWillUnmount: function() {
this._resetRecaptcha();
},
_renderRecaptcha: function(divId) { _renderRecaptcha: function(divId) {
if (!global.grecaptcha) { if (!global.grecaptcha) {
console.error("grecaptcha not loaded!"); console.error("grecaptcha not loaded!");
@ -90,12 +98,18 @@ module.exports = React.createClass({
} }
console.log("Rendering to %s", divId); console.log("Rendering to %s", divId);
global.grecaptcha.render(divId, { this._captchaWidgetId = global.grecaptcha.render(divId, {
sitekey: publicKey, sitekey: publicKey,
callback: this.props.onCaptchaResponse, callback: this.props.onCaptchaResponse,
}); });
}, },
_resetRecaptcha: function() {
if (this._captchaWidgetId !== null) {
global.grecaptcha.reset(this._captchaWidgetId);
}
},
_onCaptchaLoaded: function() { _onCaptchaLoaded: function() {
console.log("Loaded recaptcha script."); console.log("Loaded recaptcha script.");
try { try {