fix: avoid race condition when checking results
All checks were successful
deploy to cloudflare pages / deploy (push) Successful in 33s

This commit is contained in:
uku 2024-11-01 13:50:12 +01:00
parent 0065a9f9a9
commit b318f77438
Signed by: uku
SSH key fingerprint: SHA256:4P0aN6M8ajKukNi6aPOaX0LacanGYtlfjmN+m/sHY/o

View file

@ -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}