feat(navbar): update balance display and use signal for state
This commit is contained in:
parent
564601f7bc
commit
454e99f812
2 changed files with 13 additions and 12 deletions
|
@ -1,10 +1,9 @@
|
|||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { KeycloakService } from 'keycloak-angular';
|
||||
import { UserService } from '../../../service/user.service';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { CurrencyPipe } from '@angular/common';
|
||||
|
||||
import { CurrencyPipe } from '@angular/common';
|
||||
@Component({
|
||||
selector: 'app-navbar',
|
||||
templateUrl: './navbar.component.html',
|
||||
|
@ -12,21 +11,22 @@ import { CurrencyPipe } from '@angular/common';
|
|||
imports: [RouterModule, CurrencyPipe],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class NavbarComponent {
|
||||
export class NavbarComponent implements OnInit {
|
||||
isMenuOpen = false;
|
||||
private keycloakService: KeycloakService = inject(KeycloakService);
|
||||
isLoggedIn = this.keycloakService.isLoggedIn();
|
||||
|
||||
private userService = inject(UserService);
|
||||
private user = this.userService.getCurrentUser();
|
||||
balance = 0;
|
||||
|
||||
public balance = signal(0);
|
||||
|
||||
async ngOnInit() {
|
||||
const user = await firstValueFrom(this.user);
|
||||
this.balance = user?.balance ?? 0;
|
||||
ngOnInit() {
|
||||
this.user.subscribe((user) => {
|
||||
this.balance.set(user?.balance ?? 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
login() {
|
||||
try {
|
||||
const baseUrl = window.location.origin;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue