Simplify getting query params
This commit is contained in:
parent
628acf0c16
commit
808d31c790
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue