feat: add user balance updates during lootbox opening
Some checks failed
CI / Get Changed Files (pull_request) Successful in 9s
CI / Checkstyle Main (pull_request) Has been skipped
CI / Docker backend validation (pull_request) Successful in 10s
CI / Docker frontend validation (pull_request) Successful in 34s
CI / oxlint (pull_request) Successful in 22s
CI / prettier (pull_request) Failing after 26s
CI / eslint (pull_request) Successful in 34s
CI / test-build (pull_request) Successful in 43s
Some checks failed
CI / Get Changed Files (pull_request) Successful in 9s
CI / Checkstyle Main (pull_request) Has been skipped
CI / Docker backend validation (pull_request) Successful in 10s
CI / Docker frontend validation (pull_request) Successful in 34s
CI / oxlint (pull_request) Successful in 22s
CI / prettier (pull_request) Failing after 26s
CI / eslint (pull_request) Successful in 34s
CI / test-build (pull_request) Successful in 43s
This commit is contained in:
parent
d336ca77d3
commit
513ff7886b
5 changed files with 43 additions and 2 deletions
|
@ -312,9 +312,11 @@ body {
|
||||||
opacity 0.5s ease-out,
|
opacity 0.5s ease-out,
|
||||||
transform 0.5s ease-out;
|
transform 0.5s ease-out;
|
||||||
transition-delay: 0.5s;
|
transition-delay: 0.5s;
|
||||||
|
pointer-events: none; /* Prevent clicks when invisible */
|
||||||
}
|
}
|
||||||
|
|
||||||
.animation-fade.visible {
|
.animation-fade.visible {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transform: translateY(0);
|
transform: translateY(0);
|
||||||
|
pointer-events: auto; /* Enable clicks when visible */
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,12 +85,19 @@
|
||||||
class="flex justify-center gap-4 mt-8 animation-fade"
|
class="flex justify-center gap-4 mt-8 animation-fade"
|
||||||
[class.visible]="animationCompleted"
|
[class.visible]="animationCompleted"
|
||||||
>
|
>
|
||||||
<button (click)="openAgain()" class="button-primary px-6 py-2 font-semibold rounded">
|
<button
|
||||||
|
(click)="openAgain()"
|
||||||
|
class="button-primary px-6 py-2 font-semibold rounded"
|
||||||
|
[disabled]="!animationCompleted"
|
||||||
|
[attr.aria-hidden]="!animationCompleted"
|
||||||
|
>
|
||||||
Nochmal Öffnen
|
Nochmal Öffnen
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
(click)="goBack()"
|
(click)="goBack()"
|
||||||
class="bg-deep-blue hover:bg-deep-blue-contrast text-white px-6 py-2 rounded font-semibold transition"
|
class="bg-deep-blue hover:bg-deep-blue-contrast text-white px-6 py-2 rounded font-semibold transition"
|
||||||
|
[disabled]="!animationCompleted"
|
||||||
|
[attr.aria-hidden]="!animationCompleted"
|
||||||
>
|
>
|
||||||
Zurück zur Übersicht
|
Zurück zur Übersicht
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { LootboxService } from '../services/lootbox.service';
|
import { LootboxService } from '../services/lootbox.service';
|
||||||
import { LootBox, Reward } from 'app/model/LootBox';
|
import { LootBox, Reward } from 'app/model/LootBox';
|
||||||
import { NavbarComponent } from '@shared/components/navbar/navbar.component';
|
import { NavbarComponent } from '@shared/components/navbar/navbar.component';
|
||||||
|
import { UserService } from '@service/user.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-lootbox-opening',
|
selector: 'app-lootbox-opening',
|
||||||
|
@ -26,6 +27,7 @@ export default class LootboxOpeningComponent {
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private lootboxService: LootboxService,
|
private lootboxService: LootboxService,
|
||||||
|
private userService: UserService,
|
||||||
private cdr: ChangeDetectorRef
|
private cdr: ChangeDetectorRef
|
||||||
) {
|
) {
|
||||||
this.loadLootbox();
|
this.loadLootbox();
|
||||||
|
@ -58,6 +60,10 @@ export default class LootboxOpeningComponent {
|
||||||
if (!this.lootbox || this.isOpening) return;
|
if (!this.lootbox || this.isOpening) return;
|
||||||
|
|
||||||
this.resetState(true);
|
this.resetState(true);
|
||||||
|
|
||||||
|
if (this.lootbox.price) {
|
||||||
|
this.userService.updateLocalBalance(-this.lootbox.price);
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.lootboxService.purchaseLootBox(this.lootbox!.id).subscribe({
|
this.lootboxService.purchaseLootBox(this.lootbox!.id).subscribe({
|
||||||
|
@ -72,6 +78,7 @@ export default class LootboxOpeningComponent {
|
||||||
this.generateCasePrizes(reward);
|
this.generateCasePrizes(reward);
|
||||||
this.isOpening = false;
|
this.isOpening = false;
|
||||||
this.isOpen = true;
|
this.isOpen = true;
|
||||||
|
|
||||||
this.cdr.detectChanges();
|
this.cdr.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +87,12 @@ export default class LootboxOpeningComponent {
|
||||||
|
|
||||||
const rewards = this.lootbox.rewards;
|
const rewards = this.lootbox.rewards;
|
||||||
const fallback = rewards[Math.floor(Math.random() * rewards.length)];
|
const fallback = rewards[Math.floor(Math.random() * rewards.length)];
|
||||||
this.handleRewardSuccess(fallback);
|
|
||||||
|
this.wonReward = fallback;
|
||||||
|
this.generateCasePrizes(fallback);
|
||||||
|
this.isOpening = false;
|
||||||
|
this.isOpen = true;
|
||||||
|
this.cdr.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
private resetState(isOpening = false): void {
|
private resetState(isOpening = false): void {
|
||||||
|
@ -112,6 +124,12 @@ export default class LootboxOpeningComponent {
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.animationCompleted = true;
|
this.animationCompleted = true;
|
||||||
|
|
||||||
|
if (this.wonReward) {
|
||||||
|
this.userService.updateLocalBalance(this.wonReward.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.userService.refreshCurrentUser();
|
||||||
this.cdr.detectChanges();
|
this.cdr.detectChanges();
|
||||||
}, 10000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,17 @@ export class UserService {
|
||||||
this.getCurrentUser().subscribe();
|
this.getCurrentUser().subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public updateLocalBalance(amount: number): void {
|
||||||
|
const currentUser = this.currentUserSubject.getValue();
|
||||||
|
if (currentUser) {
|
||||||
|
const updatedUser = {
|
||||||
|
...currentUser,
|
||||||
|
balance: currentUser.balance + amount
|
||||||
|
};
|
||||||
|
this.currentUserSubject.next(updatedUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public createUser(id: string, username: string): Observable<User> {
|
public createUser(id: string, username: string): Observable<User> {
|
||||||
return this.http
|
return this.http
|
||||||
.post<User>('/backend/user', {
|
.post<User>('/backend/user', {
|
||||||
|
|
|
@ -31,7 +31,10 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.userSubscription = this.userService.currentUser$.subscribe((user) => {
|
this.userSubscription = this.userService.currentUser$.subscribe((user) => {
|
||||||
this.balance.set(user?.balance ?? 0);
|
this.balance.set(user?.balance ?? 0);
|
||||||
|
console.log('Updated navbar balance:', user?.balance);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.userService.refreshCurrentUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
|
Reference in a new issue