fix: avoid race condition when checking results
All checks were successful
deploy to cloudflare pages / deploy (push) Successful in 33s
All checks were successful
deploy to cloudflare pages / deploy (push) Successful in 33s
This commit is contained in:
parent
0065a9f9a9
commit
b318f77438
1 changed files with 6 additions and 2 deletions
|
@ -13,6 +13,7 @@
|
|||
|
||||
let mapPromise = $state(fetchMap());
|
||||
let gamePromise = $state(fetchGame());
|
||||
let isChecking = $state(false);
|
||||
let results: CheckResponse | null = $state(null);
|
||||
|
||||
let currentIndex = $state(0);
|
||||
|
@ -63,7 +64,8 @@
|
|||
}
|
||||
|
||||
async function checkLocation() {
|
||||
if (!playerMarker || results) return;
|
||||
if (!playerMarker || results || isChecking) return;
|
||||
isChecking = true;
|
||||
|
||||
const gameData = await gamePromise;
|
||||
|
||||
|
@ -96,6 +98,8 @@
|
|||
} else {
|
||||
alert("it seems than an error occurred");
|
||||
}
|
||||
|
||||
isChecking = false;
|
||||
}
|
||||
|
||||
async function restartGame() {
|
||||
|
@ -132,7 +136,7 @@
|
|||
|
||||
<div>
|
||||
{#if results === null}
|
||||
<button onclick={checkLocation} disabled={!playerMarker}>SUBMIT</button>
|
||||
<button onclick={checkLocation} disabled={!playerMarker || isChecking}>SUBMIT</button>
|
||||
{:else}
|
||||
<button onclick={restartGame}>NEXT</button>
|
||||
{/if}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue