1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

Migrate UIF to use takeuntilDestroyed (#15777)

This commit is contained in:
Oscar Hinton
2025-07-29 10:17:30 +02:00
committed by GitHub
parent 33ed9ac6ac
commit e3d5385661
6 changed files with 51 additions and 76 deletions

View File

@@ -1,8 +1,9 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Directive, OnDestroy, OnInit, Optional, input } from "@angular/core";
import { Directive, OnInit, Optional, input, inject, DestroyRef } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { FormGroupDirective } from "@angular/forms";
import { BehaviorSubject, catchError, filter, of, Subject, switchMap, takeUntil } from "rxjs";
import { BehaviorSubject, catchError, filter, of, switchMap } from "rxjs";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
@@ -15,8 +16,9 @@ import { FunctionReturningAwaitable, functionToObservable } from "../utils/funct
@Directive({
selector: "[formGroup][bitSubmit]",
})
export class BitSubmitDirective implements OnInit, OnDestroy {
private destroy$ = new Subject<void>();
export class BitSubmitDirective implements OnInit {
private readonly destroyRef = inject(DestroyRef);
private _loading$ = new BehaviorSubject<boolean>(false);
private _disabled$ = new BehaviorSubject<boolean>(false);
@@ -51,7 +53,7 @@ export class BitSubmitDirective implements OnInit, OnDestroy {
}),
);
}),
takeUntil(this.destroy$),
takeUntilDestroyed(),
)
.subscribe({
next: () => (this.loading = false),
@@ -60,13 +62,15 @@ export class BitSubmitDirective implements OnInit, OnDestroy {
}
ngOnInit(): void {
this.formGroupDirective.statusChanges.pipe(takeUntil(this.destroy$)).subscribe((c) => {
if (this.allowDisabledFormSubmit()) {
this._disabled$.next(false);
} else {
this._disabled$.next(c === "DISABLED");
}
});
this.formGroupDirective.statusChanges
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((c) => {
if (this.allowDisabledFormSubmit()) {
this._disabled$.next(false);
} else {
this._disabled$.next(c === "DISABLED");
}
});
}
get disabled() {
@@ -85,9 +89,4 @@ export class BitSubmitDirective implements OnInit, OnDestroy {
this.disabled = value;
this._loading$.next(value);
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
}