mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-18 10:01:58 +03:00
Fix styling comments
This commit is contained in:
parent
9de5ebd4de
commit
c2394b9161
2 changed files with 25 additions and 25 deletions
2
src/@types/global.d.ts
vendored
2
src/@types/global.d.ts
vendored
|
@ -196,7 +196,7 @@ declare global {
|
||||||
divId: string,
|
divId: string,
|
||||||
options: {
|
options: {
|
||||||
sitekey: string;
|
sitekey: string;
|
||||||
callback: () => void;
|
callback: (response: string) => void;
|
||||||
}
|
}
|
||||||
) => string;
|
) => string;
|
||||||
isReady: () => boolean;
|
isReady: () => boolean;
|
||||||
|
|
|
@ -22,12 +22,12 @@ import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
const DIV_ID = 'mx_recaptcha';
|
const DIV_ID = 'mx_recaptcha';
|
||||||
|
|
||||||
interface ICaptchaFormProps {
|
interface ICaptchaFormProps {
|
||||||
sitePublicKey: string
|
sitePublicKey: string;
|
||||||
onCaptchaResponse: () => void
|
onCaptchaResponse: (response: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ICaptchaFormState {
|
interface ICaptchaFormState {
|
||||||
errorText: string | null
|
errorText: string | null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,19 +37,19 @@ interface ICaptchaFormState {
|
||||||
@replaceableComponent("views.auth.CaptchaForm")
|
@replaceableComponent("views.auth.CaptchaForm")
|
||||||
export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICaptchaFormState> {
|
export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICaptchaFormState> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
onCaptchaResponse: () => { },
|
onCaptchaResponse: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
private _captchaWidgetId: string | null = null;
|
private captchaWidgetId: string | null = null;
|
||||||
private _recaptchaContainer: React.RefObject<HTMLDivElement> = createRef();
|
private recaptchaContainer = createRef<HTMLDivElement>();
|
||||||
|
|
||||||
state = {
|
|
||||||
errorText: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(props: ICaptchaFormProps) {
|
constructor(props: ICaptchaFormProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
errorText: null,
|
||||||
|
};
|
||||||
|
|
||||||
CountlyAnalytics.instance.track("onboarding_grecaptcha_begin");
|
CountlyAnalytics.instance.track("onboarding_grecaptcha_begin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,30 +58,30 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
||||||
// so we do this instead.
|
// so we do this instead.
|
||||||
if (this.isRecaptchaReady()) {
|
if (this.isRecaptchaReady()) {
|
||||||
// already loaded
|
// already loaded
|
||||||
this._onCaptchaLoaded();
|
this.onCaptchaLoaded();
|
||||||
} else {
|
} else {
|
||||||
console.log("Loading recaptcha script...");
|
console.log("Loading recaptcha script...");
|
||||||
window.mxOnRecaptchaLoaded = () => { this._onCaptchaLoaded(); };
|
window.mxOnRecaptchaLoaded = () => { this.onCaptchaLoaded(); };
|
||||||
const scriptTag = document.createElement('script');
|
const scriptTag = document.createElement('script');
|
||||||
scriptTag.setAttribute(
|
scriptTag.setAttribute(
|
||||||
'src', `https://www.recaptcha.net/recaptcha/api.js?onload=mxOnRecaptchaLoaded&render=explicit`,
|
'src', `https://www.recaptcha.net/recaptcha/api.js?onload=mxOnRecaptchaLoaded&render=explicit`,
|
||||||
);
|
);
|
||||||
this._recaptchaContainer.current.appendChild(scriptTag);
|
this.recaptchaContainer.current.appendChild(scriptTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this._resetRecaptcha();
|
this.resetRecaptcha();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Borrowed directly from: https://github.com/codeep/react-recaptcha-google/commit/e118fa5670fa268426969323b2e7fe77698376ba
|
// Borrowed directly from: https://github.com/codeep/react-recaptcha-google/commit/e118fa5670fa268426969323b2e7fe77698376ba
|
||||||
private isRecaptchaReady() {
|
private isRecaptchaReady(): boolean {
|
||||||
return typeof window !== "undefined" &&
|
return typeof window !== "undefined" &&
|
||||||
typeof global.grecaptcha !== "undefined" &&
|
typeof global.grecaptcha !== "undefined" &&
|
||||||
typeof global.grecaptcha.render === 'function';
|
typeof global.grecaptcha.render === 'function';
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderRecaptcha(divId) {
|
private renderRecaptcha(divId: string) {
|
||||||
if (!this.isRecaptchaReady()) {
|
if (!this.isRecaptchaReady()) {
|
||||||
console.error("grecaptcha not loaded!");
|
console.error("grecaptcha not loaded!");
|
||||||
throw new Error("Recaptcha did not load successfully");
|
throw new Error("Recaptcha did not load successfully");
|
||||||
|
@ -96,22 +96,22 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info("Rendering to %s", divId);
|
console.info("Rendering to %s", divId);
|
||||||
this._captchaWidgetId = global.grecaptcha.render(divId, {
|
this.captchaWidgetId = global.grecaptcha.render(divId, {
|
||||||
sitekey: publicKey,
|
sitekey: publicKey,
|
||||||
callback: this.props.onCaptchaResponse,
|
callback: this.props.onCaptchaResponse,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _resetRecaptcha() {
|
private resetRecaptcha() {
|
||||||
if (this._captchaWidgetId !== null) {
|
if (this.captchaWidgetId !== null) {
|
||||||
global.grecaptcha.reset(this._captchaWidgetId);
|
global.grecaptcha.reset(this.captchaWidgetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onCaptchaLoaded() {
|
private onCaptchaLoaded() {
|
||||||
console.log("Loaded recaptcha script.");
|
console.log("Loaded recaptcha script.");
|
||||||
try {
|
try {
|
||||||
this._renderRecaptcha(DIV_ID);
|
this.renderRecaptcha(DIV_ID);
|
||||||
// clear error if re-rendered
|
// clear error if re-rendered
|
||||||
this.setState({
|
this.setState({
|
||||||
errorText: null,
|
errorText: null,
|
||||||
|
@ -136,12 +136,12 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={this._recaptchaContainer}>
|
<div ref={this.recaptchaContainer}>
|
||||||
<p>{_t(
|
<p>{_t(
|
||||||
"This homeserver would like to make sure you are not a robot.",
|
"This homeserver would like to make sure you are not a robot.",
|
||||||
)}</p>
|
)}</p>
|
||||||
<div id={DIV_ID} />
|
<div id={DIV_ID} />
|
||||||
{error}
|
{ error }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue