[DURACOM-191] Refactoring in order to remove nested subscriptions

This commit is contained in:
Giuseppe Digilio
2024-03-13 12:26:14 +01:00
parent 0ff19db071
commit e03f68d239

View File

@@ -8,6 +8,7 @@ import {
import {
BehaviorSubject,
combineLatest,
EMPTY,
Observable,
of,
} from 'rxjs';
@@ -15,6 +16,7 @@ import {
map,
switchMap,
take,
tap,
} from 'rxjs/operators';
import { isNotEmpty } from '../../shared/empty.util';
@@ -84,14 +86,12 @@ export class GoogleRecaptchaService {
return res.hasSucceeded && res.payload && isNotEmpty(res.payload.values) && res.payload.values[0].toLowerCase() === 'true';
}),
);
registrationVerification$.subscribe(registrationVerification => {
if (registrationVerification) {
this.loadRecaptchaProperties();
}
});
registrationVerification$.pipe(
switchMap((registrationVerification: boolean) => registrationVerification ? this.loadRecaptchaProperties() : EMPTY),
).subscribe();
}
loadRecaptchaProperties() {
loadRecaptchaProperties(): Observable<any> {
const recaptchaKeyRD$ = this.configService.findByPropertyName('google.recaptcha.key.site').pipe(
getFirstCompletedRemoteData(),
);
@@ -101,7 +101,8 @@ export class GoogleRecaptchaService {
const recaptchaModeRD$ = this.configService.findByPropertyName('google.recaptcha.mode').pipe(
getFirstCompletedRemoteData(),
);
combineLatest([recaptchaVersionRD$, recaptchaModeRD$, recaptchaKeyRD$]).subscribe(([recaptchaVersionRD, recaptchaModeRD, recaptchaKeyRD]) => {
return combineLatest([recaptchaVersionRD$, recaptchaModeRD$, recaptchaKeyRD$]).pipe(
tap(([recaptchaVersionRD, recaptchaModeRD, recaptchaKeyRD]) => {
if (
this.cookieService.get('klaro-anonymous') && this.cookieService.get('klaro-anonymous')[CAPTCHA_NAME] &&
@@ -134,7 +135,8 @@ export class GoogleRecaptchaService {
this.loadScript(captchaUrl);
}
}
});
}),
);
}
/**
@@ -188,7 +190,7 @@ export class GoogleRecaptchaService {
}
refreshCaptchaScript = () => {
this.loadRecaptchaProperties();
this.loadRecaptchaProperties().subscribe();
};
}