This repository has been archived on 2025-06-18. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
casino/frontend/src/app/shared/components/navbar/navbar.component.ts

54 lines
1.3 KiB
TypeScript

import {
ChangeDetectionStrategy,
Component,
EventEmitter,
inject,
OnDestroy,
OnInit,
Output,
signal,
} from '@angular/core';
import { RouterModule } from '@angular/router';
import { AuthService } from '@service/auth.service';
import { Subscription } from 'rxjs';
import { AnimatedNumberComponent } from '@blackjack/components/animated-number/animated-number.component';
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
standalone: true,
imports: [RouterModule, AnimatedNumberComponent],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NavbarComponent implements OnInit, OnDestroy {
isMenuOpen = false;
private authService: AuthService = inject(AuthService);
isLoggedIn = signal(this.authService.isLoggedIn());
private authSubscription!: Subscription;
public balance = signal(0);
@Output() showLogin = new EventEmitter<void>();
@Output() showRegister = new EventEmitter<void>();
ngOnInit() {
this.authSubscription = this.authService.userSubject.subscribe({
next: (user) => {
this.balance.set(user?.balance ?? 0);
this.isLoggedIn.set(this.authService.isLoggedIn());
},
});
}
ngOnDestroy() {
this.authSubscription.unsubscribe();
}
logout() {
this.authService.logout();
}
toggleMenu() {
this.isMenuOpen = !this.isMenuOpen;
}
}