Better async at the start

This commit is contained in:
2024-11-24 21:05:39 +01:00
parent bb78abe50b
commit ba53552f40

View File

@@ -24,9 +24,9 @@ document.addEventListener('alpine:init', () => {
resultGuesses: Alpine.$persist('').as('resultGuesses'), resultGuesses: Alpine.$persist('').as('resultGuesses'),
resultTimeTaken: Alpine.$persist('').as('resultTimeTaken'), resultTimeTaken: Alpine.$persist('').as('resultTimeTaken'),
init() { async init() {
/** Initialise the application after loading */ /** Initialise the application after loading */
this.getGameID(); await this.getGameID();
setInterval(() => { setInterval(() => {
// Update counter to next game (midnight UTC, fetched from API) every second // Update counter to next game (midnight UTC, fetched from API) every second
this.countDownTimer(); this.countDownTimer();
@@ -162,6 +162,7 @@ document.addEventListener('alpine:init', () => {
}, },
countDownTimer(){ countDownTimer(){
/** Update counter to next game (midnight UTC, fetched from API) */ /** Update counter to next game (midnight UTC, fetched from API) */
if (this.gameFetchedAt === null) { return; }
let now = new Date(); let now = new Date();
let gameDataFetched = new Date(this.gameFetchedAt); let gameDataFetched = new Date(this.gameFetchedAt);
let nextGameStart = gameDataFetched.setSeconds(gameDataFetched.getSeconds() + this.nextGameIn); let nextGameStart = gameDataFetched.setSeconds(gameDataFetched.getSeconds() + this.nextGameIn);