Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add loading spinner to login button for slow wifi feedback #73

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/frontend/src/app/features/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@
[disabled]="loginForm.invalid"
[ngClass]="{
'bg-gray-700 hover:bg-gray-700': loginForm.invalid,
'bg-indigo-600 hover:bg-indigo-700': loginForm.valid
'bg-indigo-600 hover:bg-indigo-700': loginForm.valid,
}"
>
Log in
@if (isLoading){
<app-button-spinner />
}@else{ Log in }
</button>
</div>
</form>
Expand Down
5 changes: 5 additions & 0 deletions apps/frontend/src/app/features/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ErrorComponent } from '../../shared/feedback/error/error.component'
import { LoadingComponent } from '../../shared/feedback/loading/loading.component'
import { SuccessComponent } from '../../shared/feedback/success/success.component'
import { RouterLink } from '@angular/router'
import { ButtonSpinnerComponent } from '../../shared/feedback/button-spinner/button-spinner.component'

@Component({
selector: 'app-login',
Expand All @@ -25,6 +26,7 @@ import { RouterLink } from '@angular/router'
LoadingComponent,
SuccessComponent,
RouterLink,
ButtonSpinnerComponent,
],
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
Expand All @@ -34,6 +36,7 @@ export class LoginComponent {
protected hasError = false
protected errorMessage = ''
protected successMessage = ''
protected isLoading = false

constructor(
private authService: AuthService,
Expand All @@ -46,6 +49,7 @@ export class LoginComponent {
}

async logInUsingPrivateKey() {
this.isLoading = true
const privateKey = this.loginForm.value.privateKey
const couldLogin = await this.authService.loginUsingPrivateKey(privateKey)

Expand All @@ -59,6 +63,7 @@ export class LoginComponent {
'Failed to login. Please check your private key or register a new account.'
this.loginForm.reset()
}
this.isLoading = false
}

errorAction = (): void => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<svg
class="animate-spin -ml-1 mr-3 h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
class="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
stroke-width="4"
></circle>
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { ButtonSpinnerComponent } from './button-spinner.component'

describe('ButtonSpinnerComponent', () => {
let component: ButtonSpinnerComponent
let fixture: ComponentFixture<ButtonSpinnerComponent>

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ButtonSpinnerComponent],
}).compileComponents()

fixture = TestBed.createComponent(ButtonSpinnerComponent)
component = fixture.componentInstance
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from '@angular/core'

@Component({
selector: 'app-button-spinner',
standalone: true,
imports: [],
templateUrl: './button-spinner.component.html',
styleUrl: './button-spinner.component.css',
})
export class ButtonSpinnerComponent {}