feat(blackjack): refresh user balance on game state change
This commit is contained in:
parent
08b12d238e
commit
e983b21e07
7 changed files with 48 additions and 19 deletions
|
@ -1,9 +1,10 @@
|
|||
import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, inject, OnInit, OnDestroy, signal } from '@angular/core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { KeycloakService } from 'keycloak-angular';
|
||||
|
||||
import { CurrencyPipe } from '@angular/common';
|
||||
import { UserService } from '@service/user.service';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-navbar',
|
||||
templateUrl: './navbar.component.html',
|
||||
|
@ -11,22 +12,27 @@ import { UserService } from '@service/user.service';
|
|||
imports: [RouterModule, CurrencyPipe],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class NavbarComponent implements OnInit {
|
||||
export class NavbarComponent implements OnInit, OnDestroy {
|
||||
isMenuOpen = false;
|
||||
private keycloakService: KeycloakService = inject(KeycloakService);
|
||||
isLoggedIn = this.keycloakService.isLoggedIn();
|
||||
|
||||
private userService = inject(UserService);
|
||||
private user = this.userService.getCurrentUser();
|
||||
|
||||
private userSubscription: Subscription | undefined;
|
||||
public balance = signal(0);
|
||||
|
||||
ngOnInit() {
|
||||
this.user.subscribe((user) => {
|
||||
this.userSubscription = this.userService.currentUser$.subscribe((user) => {
|
||||
this.balance.set(user?.balance ?? 0);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.userSubscription) {
|
||||
this.userSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
login() {
|
||||
try {
|
||||
const baseUrl = window.location.origin;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue