From 40079e1145fdb391fcdc77d4edeb7e725feb1006 Mon Sep 17 00:00:00 2001 From: Samuel Ortion Date: Mon, 8 Jan 2024 20:06:42 +0100 Subject: [PATCH] fix: Second play, now displays the form --- controllers/api.js | 1 + controllers/quizz.js | 7 ++----- public/javascripts/game.js | 13 ++++++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/controllers/api.js b/controllers/api.js index d9b9e84..ee03f50 100755 --- a/controllers/api.js +++ b/controllers/api.js @@ -36,6 +36,7 @@ function quizz(req, res) { res.json({ species, audio }).send(); debug("Quizz sent"); quizzController.cacheQuizz(); // Prepare the next question in advance. + debug("New quizz cached"); }) .catch(error => { debug("Faced error while generating quizz"); diff --git a/controllers/quizz.js b/controllers/quizz.js index def71ed..36fc019 100755 --- a/controllers/quizz.js +++ b/controllers/quizz.js @@ -22,9 +22,10 @@ async function getQuizzCached(region, locale, size) { } async function cacheQuizz(region, locale, size) { - let quizz = generateQuizz(region, locale, size); + let quizz = await generateQuizz(region, locale, size); let key = quizzKey(region, locale, size); cache.push(key, quizz); + return quizz; } async function generateQuizz(region, locale, size) { @@ -66,10 +67,6 @@ async function generateQuizz(region, locale, size) { async function getSpeciesSelection(region, number) { const regionCode = region; - // const { lat, lng } = coordinates; - // const region = await getRegion(lat, lng); - // const regionCode = await getRegionCode(region); - // const regionCode = region.country_code; const speciesList = await getSpeciesList(regionCode); const speciesSelection = choices(speciesList, number); debug("Species proposals:", speciesSelection) diff --git a/public/javascripts/game.js b/public/javascripts/game.js index 4614e6f..0208e12 100755 --- a/public/javascripts/game.js +++ b/public/javascripts/game.js @@ -15,6 +15,8 @@ let resultSciName = document.querySelector('.game-results-step .species .sci'); const API_VERSION = "0"; +let region = 'FR'; + function geolocationStep() { if (map != undefined) geolocationHandler(); @@ -25,20 +27,16 @@ function geolocationStep() { function regionCoder() { // Start by disallowing geolocation step gameMapStep.classList.add('none'); - // Then allow the quizz step - gameQuizzStep.classList.remove('none'); - // Retrieve coordinates from former done geolocation (TODO: fix the need of cookie) const coordinates = getCoordinates(); let [lat, lon] = coordinates; client.getRegion(lat, lon).then(data => { - let { region } = data; - console.log(region); - quizzStep(region); + region = data.region; + quizzStep(); }); } -function quizzStep(region) { +function quizzStep() { client.getQuizz(region) .then(quizz => { displayQuizz(quizz); @@ -51,6 +49,7 @@ function quizzStep(region) { function displayQuizz(quizz) { audio.src = quizz.audio; audio.classList.remove("none"); // Display the audio controls + gameQuizzStep.classList.remove("none"); audio.play(); proposals.innerHTML = ""; quizz.species.forEach(sp => {