refactor(auth): replace UserService with AuthService usage
Some checks failed
CI / Get Changed Files (pull_request) Successful in 37s
CI / Docker backend validation (pull_request) Successful in 14s
CI / Docker frontend validation (pull_request) Successful in 51s
CI / eslint (pull_request) Successful in 42s
CI / oxlint (pull_request) Successful in 32s
CI / Checkstyle Main (pull_request) Successful in 1m2s
CI / prettier (pull_request) Failing after 27s
CI / test-build (pull_request) Successful in 59s

This commit is contained in:
Jan-Marlon Leibl 2025-05-07 18:02:12 +02:00
commit 226675de03
Signed by: jleibl
GPG key ID: 300B2F906DC6F1D5
6 changed files with 38 additions and 86 deletions

View file

@ -14,6 +14,7 @@ import { NavbarComponent } from '@shared/components/navbar/navbar.component';
import { UserService } from '@service/user.service';
import { timer } from 'rxjs';
import { DebtDialogComponent } from '@shared/components/debt-dialog/debt-dialog.component';
import { AuthService } from '@service/auth.service';
@Component({
selector: 'app-blackjack',
@ -34,6 +35,7 @@ import { DebtDialogComponent } from '@shared/components/debt-dialog/debt-dialog.
export default class BlackjackComponent implements OnInit {
private router = inject(Router);
private userService = inject(UserService);
private authService = inject(AuthService);
private blackjackService = inject(BlackjackService);
dealerCards = signal<Card[]>([]);
@ -51,15 +53,8 @@ export default class BlackjackComponent implements OnInit {
debtAmount = signal(0);
ngOnInit(): void {
// Initial user load from server
this.userService.getCurrentUser().subscribe((user) => {
if (user) {
this.balance.set(user.balance);
}
});
// Subscribe to user updates for real-time balance changes
this.userService.currentUser$.subscribe((user) => {
this.authService.userSubject.subscribe((user) => {
if (user) {
this.balance.set(user.balance);
}
@ -95,15 +90,10 @@ export default class BlackjackComponent implements OnInit {
// Get the latest balance before showing the result dialog
timer(1000).subscribe(() => {
this.userService.getCurrentUser().subscribe((user) => {
if (user) {
this.balance.set(user.balance);
// Show the result dialog after updating the balance
timer(500).subscribe(() => {
this.showGameResult.set(true);
console.log('Game result dialog shown after delay');
});
}
// Show the result dialog after refreshing user data
timer(500).subscribe(() => {
this.showGameResult.set(true);
console.log('Game result dialog shown after delay');
});
});
}
@ -186,15 +176,11 @@ export default class BlackjackComponent implements OnInit {
// Wait a bit to ensure the backend has finished processing
timer(1000).subscribe(() => {
this.userService.getCurrentUser().subscribe((user) => {
if (user) {
this.balance.set(user.balance);
if (user.balance < 0) {
this.debtAmount.set(Math.abs(user.balance));
this.showDebtDialog.set(true);
}
}
});
const user = this.authService.currentUserValue;
if (user && user.balance < 0) {
this.debtAmount.set(Math.abs(user.balance));
this.showDebtDialog.set(true);
}
});
this.isActionInProgress.set(false);
@ -210,13 +196,6 @@ export default class BlackjackComponent implements OnInit {
onCloseGameResult(): void {
console.log('Closing game result dialog');
this.showGameResult.set(false);
// Refresh the balance when dialog is closed and update local state
this.userService.getCurrentUser().subscribe((user) => {
if (user) {
this.balance.set(user.balance);
}
});
}
onCloseDebtDialog(): void {