Simplify getting query params

This commit is contained in:
Alec Rippberger 2024-10-18 23:03:37 -05:00
parent 628acf0c16
commit 808d31c790
No known key found for this signature in database
GPG Key ID: 9DD8DA583B28154A
1 changed files with 16 additions and 22 deletions

View File

@ -2,7 +2,7 @@ import { CommonModule } from "@angular/common";
import { Component, ElementRef, Input, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core"; import { Component, ElementRef, Input, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core";
import { FormBuilder, FormControl, ReactiveFormsModule, Validators } from "@angular/forms"; import { FormBuilder, FormControl, ReactiveFormsModule, Validators } from "@angular/forms";
import { ActivatedRoute, Router, RouterModule } from "@angular/router"; import { ActivatedRoute, Router, RouterModule } from "@angular/router";
import { firstValueFrom, of, Subject, switchMap, take, takeUntil } from "rxjs"; import { firstValueFrom, Subject, take, takeUntil } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module"; import { JslibModule } from "@bitwarden/angular/jslib.module";
import { import {
@ -468,8 +468,6 @@ export class LoginComponent implements OnInit, OnDestroy {
this.formGroup.controls.rememberEmail.setValue(true); this.formGroup.controls.rememberEmail.setValue(true);
} }
} }
await this.getLoginWithDevice(this.emailFormControl.value);
} }
private focusInput() { private focusInput() {
@ -491,28 +489,24 @@ export class LoginComponent implements OnInit, OnDestroy {
let paramEmailIsSet = false; let paramEmailIsSet = false;
this.activatedRoute?.queryParams const params = await firstValueFrom(this.activatedRoute.queryParams);
.pipe(
switchMap((params) => {
if (!params) {
// If no params,loadEmailSettings from state
return this.loadEmailSettings();
}
const qParamsEmail = params.email; if (params) {
const qParamsEmail = params.email;
// If there is an email in the query params, set that email as the form field value // If there is an email in the query params, set that email as the form field value
if (qParamsEmail != null && qParamsEmail.indexOf("@") > -1) { if (qParamsEmail != null && qParamsEmail.indexOf("@") > -1) {
this.formGroup.controls.email.setValue(qParamsEmail); this.formGroup.controls.email.setValue(qParamsEmail);
paramEmailIsSet = true; paramEmailIsSet = true;
} }
}
// If there is no email in the query params, loadEmailSettings from state // If there are no params or no email in the query params, loadEmailSettings from state
return paramEmailIsSet ? of(null) : this.loadEmailSettings(); if (!paramEmailIsSet) {
}), await this.loadEmailSettings();
takeUntil(this.destroy$), }
)
.subscribe(); await this.getLoginWithDevice(this.emailFormControl.value);
// Backup check to handle unknown case where activatedRoute is not available // Backup check to handle unknown case where activatedRoute is not available
// This shouldn't happen under normal circumstances // This shouldn't happen under normal circumstances