mirror of
https://github.com/aquatix/alfagok.git
synced 2025-12-07 01:35:11 +01:00
Moved gameID loading into Alpine store function
This commit is contained in:
@@ -1,14 +1,6 @@
|
|||||||
/* API calls **/
|
/* 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) {
|
async function doGuess(guessWord) {
|
||||||
|
Alpine.store('alfagok').loading = true;
|
||||||
if (guessWord === '') {
|
if (guessWord === '') {
|
||||||
console.log('Nothing filled in');
|
console.log('Nothing filled in');
|
||||||
Alpine.store('alfagok').guessError = 'Vul een woord 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 response = await fetch('/api/guess/' + guessWord);
|
||||||
let result = await response.json();
|
let result = await response.json();
|
||||||
console.log(result);
|
console.log(result);
|
||||||
|
|
||||||
|
Alpine.store('alfagok').loading = false;
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
console.log('Error occurred during guess');
|
console.log('Error occurred during guess');
|
||||||
if (result.error === 'Word not in dictionary') {
|
if (result.error === 'Word not in dictionary') {
|
||||||
Alpine.store('alfagok').guessError = 'Woord komt niet in de woordenlijst voor';
|
Alpine.store('alfagok').guessError = 'Woord komt niet in de woordenlijst voor';
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (result.hint && result.hint === 'after') {
|
if (result.hint && result.hint === 'after') {
|
||||||
console.log('na');
|
console.log('na');
|
||||||
@@ -39,7 +34,6 @@ async function doGuess(guessWord) {
|
|||||||
if (result.hint && result.hint === 'it') {
|
if (result.hint && result.hint === 'it') {
|
||||||
console.log('gevonden');
|
console.log('gevonden');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Time formatting **/
|
/* Time formatting **/
|
||||||
|
|||||||
@@ -11,17 +11,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('alpine:init', () => {
|
document.addEventListener('alpine:init', () => {
|
||||||
/*
|
|
||||||
const gameIDResult = await fetch('/api/game')
|
|
||||||
if (!gameIDResult.ok) {
|
|
||||||
throw new Error(`${gameIDResult.status}: ${await gameIDResult.text()}`);
|
|
||||||
}
|
|
||||||
Alpine.store('alfagok', {
|
|
||||||
gameID: await gameIDResult.json().game,
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
Alpine.store('alfagok', {
|
Alpine.store('alfagok', {
|
||||||
gameID: 0,
|
gameID: 0,
|
||||||
|
|
||||||
|
loading: false,
|
||||||
|
|
||||||
winTime: null,
|
winTime: null,
|
||||||
startTime: null,
|
startTime: null,
|
||||||
|
|
||||||
@@ -32,7 +26,20 @@
|
|||||||
guessValue: '',
|
guessValue: '',
|
||||||
|
|
||||||
guessError: '',
|
guessError: '',
|
||||||
})
|
|
||||||
|
async getGameID() {
|
||||||
|
this.loading = true;
|
||||||
|
console.log('Loading gameID...');
|
||||||
|
let response = await fetch('/api/game');
|
||||||
|
let result = await response.json();
|
||||||
|
console.log(result);
|
||||||
|
this.loading = false;
|
||||||
|
if (result.game) {
|
||||||
|
return this.gameID = result.game;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}),
|
||||||
|
|
||||||
Alpine.store('darkMode', {
|
Alpine.store('darkMode', {
|
||||||
init() {
|
init() {
|
||||||
@@ -114,7 +121,8 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('alpine:initialized', () => {
|
document.addEventListener('alpine:initialized', () => {
|
||||||
Alpine.store('alfagok').gameID = getGameID();
|
//Alpine.store('alfagok').gameID = getGameID();
|
||||||
|
Alpine.store('alfagok').getGameID();
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user