From 49853d99c68b59d00fd1b08b997cd8139a7877f4 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 26 Oct 2025 02:33:55 +0100 Subject: [PATCH] Enhance login form with keep signed in functionality and disable button during submission --- .../app/components/login/login.component.html | 4 ++-- .../app/components/login/login.component.ts | 22 ++++++++++++++++++- src/angular/frontend/src/form.scss | 10 +++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/angular/frontend/src/app/components/login/login.component.html b/src/angular/frontend/src/app/components/login/login.component.html index f6ef100..7be8b1f 100644 --- a/src/angular/frontend/src/app/components/login/login.component.html +++ b/src/angular/frontend/src/app/components/login/login.component.html @@ -20,12 +20,12 @@
- +
- +
diff --git a/src/angular/frontend/src/app/components/login/login.component.ts b/src/angular/frontend/src/app/components/login/login.component.ts index 1ae5019..57c6c89 100644 --- a/src/angular/frontend/src/app/components/login/login.component.ts +++ b/src/angular/frontend/src/app/components/login/login.component.ts @@ -2,6 +2,7 @@ import {Component, inject, signal} from '@angular/core'; import {FormControl, FormGroup, FormsModule, FormSubmittedEvent, ReactiveFormsModule} from '@angular/forms'; import {AuthService, ValidateCredentialsCommand} from '../../clients/gandalf/mithrandir/auth.service'; import {Router} from '@angular/router'; +import {takeUntilDestroyed, toObservable} from '@angular/core/rxjs-interop'; @Component({ selector: 'app-login', @@ -21,13 +22,31 @@ export class LoginComponent { protected loginFormGroup = new FormGroup({ usernameOrEmail: new FormControl('housemaster'), password: new FormControl('kR0pNCspBKx8lOzAIch5'), - keep: new FormControl(false), + keepSignedIn: new FormControl(false), }); protected errors = signal([]); + protected submitting = signal(true); + + constructor() { + + toObservable(this.submitting) + .pipe( + takeUntilDestroyed(), + ) + .subscribe(x => { + if (x) { + this.loginFormGroup.disable(); + } else { + this.loginFormGroup.enable(); + } + }) + + } protected async onSubmit($event: Event): Promise { $event.preventDefault(); + this.submitting.set(true) this.errors.set([]); @@ -37,6 +56,7 @@ export class LoginComponent { await this.auth.loginAsync(this.loginFormGroup.value as unknown as ValidateCredentialsCommand, error => { this.errors.set([...this.errors(), error.error.trim()]); + this.submitting.set(false) }); console.log('login successful'); diff --git a/src/angular/frontend/src/form.scss b/src/angular/frontend/src/form.scss index 2655c68..d6b2b8a 100644 --- a/src/angular/frontend/src/form.scss +++ b/src/angular/frontend/src/form.scss @@ -43,6 +43,16 @@ form { padding: 0.5em; border-radius: 0.5em; background-color: var(--neutral-80); + + &:disabled { + color: var(--neutral-60); + } + } + + &:has(input[disabled]) { + label { + color: var(--neutral-50); + } } &:has(input[required]:not([type="radio"])) {