From 67188ced8bfb364870bef1dbd39fa75cf39a6bc1 Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Mon, 4 Nov 2024 22:22:44 +0100 Subject: [PATCH] Moved gameID loading into Alpine store function --- src/alfagok/static/game.js | 14 ++++---------- src/alfagok/templates/index.html | 30 +++++++++++++++++++----------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/alfagok/static/game.js b/src/alfagok/static/game.js index 707ed9d..46886ba 100644 --- a/src/alfagok/static/game.js +++ b/src/alfagok/static/game.js @@ -1,14 +1,6 @@ /* API calls **/ -async function getGameID() { - let response = await fetch('/api/game'); - let result = await response.json(); - console.log(result); - if (result.game) { - return result.game; - } -} - async function doGuess(guessWord) { + Alpine.store('alfagok').loading = true; if (guessWord === '') { console.log('Nothing filled in'); Alpine.store('alfagok').guessError = 'Vul een woord in'; @@ -22,11 +14,14 @@ async function doGuess(guessWord) { let response = await fetch('/api/guess/' + guessWord); let result = await response.json(); console.log(result); + + Alpine.store('alfagok').loading = false; if (result.error) { console.log('Error occurred during guess'); if (result.error === 'Word not in dictionary') { Alpine.store('alfagok').guessError = 'Woord komt niet in de woordenlijst voor'; } + return; } if (result.hint && result.hint === 'after') { console.log('na'); @@ -39,7 +34,6 @@ async function doGuess(guessWord) { if (result.hint && result.hint === 'it') { console.log('gevonden'); } - } /* Time formatting **/ diff --git a/src/alfagok/templates/index.html b/src/alfagok/templates/index.html index 36eeebb..a77a1c2 100644 --- a/src/alfagok/templates/index.html +++ b/src/alfagok/templates/index.html @@ -11,17 +11,11 @@