feat: game starts after accept
This commit is contained in:
@@ -46,6 +46,12 @@
|
|||||||
Accept
|
Accept
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="challenge-actions" *ngIf="challenge.status === 'accepted' && challenge.gameId">
|
||||||
|
<button type="button" class="btn btn-accept" (click)="openGame(challenge)">
|
||||||
|
Play
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -83,6 +89,12 @@
|
|||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="challenge-actions" *ngIf="challenge.status === 'accepted' && challenge.gameId">
|
||||||
|
<button type="button" class="btn btn-accept" (click)="openGame(challenge)">
|
||||||
|
Play
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -88,10 +88,14 @@ export class ChallengesComponent implements OnInit, OnDestroy {
|
|||||||
this.challengeService.acceptChallenge(challenge.id)
|
this.challengeService.acceptChallenge(challenge.id)
|
||||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: () => {
|
next: (acceptedChallenge) => {
|
||||||
this.challengeEventService.onChallengeAccepted(challenge);
|
this.challengeEventService.onChallengeAccepted(acceptedChallenge);
|
||||||
this.loadChallenges();
|
this.loadChallenges();
|
||||||
// Navigate to game (if backend creates game automatically)
|
if (acceptedChallenge.gameId) {
|
||||||
|
void this.router.navigate(['/game', acceptedChallenge.gameId]);
|
||||||
|
} else {
|
||||||
|
this.errorMessage = 'Challenge accepted, but no game was created.';
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
this.errorMessage = getErrorMessage(error, 'Failed to accept challenge');
|
this.errorMessage = getErrorMessage(error, 'Failed to accept challenge');
|
||||||
@@ -130,6 +134,14 @@ export class ChallengesComponent implements OnInit, OnDestroy {
|
|||||||
void this.router.navigate(['/']);
|
void this.router.navigate(['/']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openGame(challenge: Challenge): void {
|
||||||
|
if (!challenge.gameId) {
|
||||||
|
this.errorMessage = 'Missing game id for this challenge.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void this.router.navigate(['/game', challenge.gameId]);
|
||||||
|
}
|
||||||
|
|
||||||
getTimeControlDisplay(challenge: Challenge): string {
|
getTimeControlDisplay(challenge: Challenge): string {
|
||||||
const { limit, increment } = challenge.timeControl;
|
const { limit, increment } = challenge.timeControl;
|
||||||
if (!limit || !increment) {
|
if (!limit || !increment) {
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ export class ChallengeService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
acceptChallenge(challengeId: string): Observable<void> {
|
acceptChallenge(challengeId: string): Observable<Challenge> {
|
||||||
return this.http.post<void>(
|
return this.http.post<Challenge>(
|
||||||
`${this.challengeBaseUrl}/${challengeId}/accept`,
|
`${this.challengeBaseUrl}/${challengeId}/accept`,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user