1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

[PM-2135] feat: add onDestroy handler

This commit is contained in:
Andreas Coroiu
2023-05-05 15:34:06 +02:00
parent 7ea7244b3d
commit cdd801165d

View File

@@ -1,5 +1,6 @@
import { Directive, EventEmitter, Input, OnInit, Output } from "@angular/core"; import { Directive, EventEmitter, Input, OnDestroy, OnInit, Output } from "@angular/core";
import { ControlValueAccessor, FormControl, Validators } from "@angular/forms"; import { ControlValueAccessor, FormControl, Validators } from "@angular/forms";
import { Subject, takeUntil } from "rxjs";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction"; import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction";
@@ -18,7 +19,7 @@ import { Verification } from "@bitwarden/common/types/verification";
selector: "app-user-verification", selector: "app-user-verification",
}) })
// eslint-disable-next-line rxjs-angular/prefer-takeuntil // eslint-disable-next-line rxjs-angular/prefer-takeuntil
export class UserVerificationComponent implements ControlValueAccessor, OnInit { export class UserVerificationComponent implements ControlValueAccessor, OnInit, OnDestroy {
private _invalidSecret = false; private _invalidSecret = false;
@Input() @Input()
get invalidSecret() { get invalidSecret() {
@@ -34,7 +35,7 @@ export class UserVerificationComponent implements ControlValueAccessor, OnInit {
} }
@Output() invalidSecretChange = new EventEmitter<boolean>(); @Output() invalidSecretChange = new EventEmitter<boolean>();
usesKeyConnector = false; usesKeyConnector = true;
disableRequestOTP = false; disableRequestOTP = false;
sentCode = false; sentCode = false;
@@ -50,6 +51,7 @@ export class UserVerificationComponent implements ControlValueAccessor, OnInit {
]); ]);
private onChange: (value: Verification) => void; private onChange: (value: Verification) => void;
private destroy$ = new Subject<void>();
constructor( constructor(
private keyConnectorService: KeyConnectorService, private keyConnectorService: KeyConnectorService,
@@ -61,8 +63,9 @@ export class UserVerificationComponent implements ControlValueAccessor, OnInit {
this.usesKeyConnector = await this.keyConnectorService.getUsesKeyConnector(); this.usesKeyConnector = await this.keyConnectorService.getUsesKeyConnector();
this.processChanges(this.secret.value); this.processChanges(this.secret.value);
// eslint-disable-next-line rxjs-angular/prefer-takeuntil this.secret.valueChanges
this.secret.valueChanges.subscribe((secret: string) => this.processChanges(secret)); .pipe(takeUntil(this.destroy$))
.subscribe((secret: string) => this.processChanges(secret));
} }
requestOTP = async () => { requestOTP = async () => {
@@ -98,6 +101,11 @@ export class UserVerificationComponent implements ControlValueAccessor, OnInit {
} }
} }
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
protected processChanges(secret: string) { protected processChanges(secret: string) {
this.invalidSecret = false; this.invalidSecret = false;