fix: Second play, now displays the form

This commit is contained in:
Samuel Ortion 2024-01-08 20:06:42 +01:00
parent 94d30121d4
commit 40079e1145
3 changed files with 9 additions and 12 deletions

View File

@ -36,6 +36,7 @@ function quizz(req, res) {
res.json({ species, audio }).send(); res.json({ species, audio }).send();
debug("Quizz sent"); debug("Quizz sent");
quizzController.cacheQuizz(); // Prepare the next question in advance. quizzController.cacheQuizz(); // Prepare the next question in advance.
debug("New quizz cached");
}) })
.catch(error => { .catch(error => {
debug("Faced error while generating quizz"); debug("Faced error while generating quizz");

View File

@ -22,9 +22,10 @@ async function getQuizzCached(region, locale, size) {
} }
async function cacheQuizz(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); let key = quizzKey(region, locale, size);
cache.push(key, quizz); cache.push(key, quizz);
return quizz;
} }
async function generateQuizz(region, locale, size) { async function generateQuizz(region, locale, size) {
@ -66,10 +67,6 @@ async function generateQuizz(region, locale, size) {
async function getSpeciesSelection(region, number) { async function getSpeciesSelection(region, number) {
const regionCode = region; 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 speciesList = await getSpeciesList(regionCode);
const speciesSelection = choices(speciesList, number); const speciesSelection = choices(speciesList, number);
debug("Species proposals:", speciesSelection) debug("Species proposals:", speciesSelection)

View File

@ -15,6 +15,8 @@ let resultSciName = document.querySelector('.game-results-step .species .sci');
const API_VERSION = "0"; const API_VERSION = "0";
let region = 'FR';
function geolocationStep() { function geolocationStep() {
if (map != undefined) if (map != undefined)
geolocationHandler(); geolocationHandler();
@ -25,20 +27,16 @@ function geolocationStep() {
function regionCoder() { function regionCoder() {
// Start by disallowing geolocation step // Start by disallowing geolocation step
gameMapStep.classList.add('none'); 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) // Retrieve coordinates from former done geolocation (TODO: fix the need of cookie)
const coordinates = getCoordinates(); const coordinates = getCoordinates();
let [lat, lon] = coordinates; let [lat, lon] = coordinates;
client.getRegion(lat, lon).then(data => { client.getRegion(lat, lon).then(data => {
let { region } = data; region = data.region;
console.log(region); quizzStep();
quizzStep(region);
}); });
} }
function quizzStep(region) { function quizzStep() {
client.getQuizz(region) client.getQuizz(region)
.then(quizz => { .then(quizz => {
displayQuizz(quizz); displayQuizz(quizz);
@ -51,6 +49,7 @@ function quizzStep(region) {
function displayQuizz(quizz) { function displayQuizz(quizz) {
audio.src = quizz.audio; audio.src = quizz.audio;
audio.classList.remove("none"); // Display the audio controls audio.classList.remove("none"); // Display the audio controls
gameQuizzStep.classList.remove("none");
audio.play(); audio.play();
proposals.innerHTML = ""; proposals.innerHTML = "";
quizz.species.forEach(sp => { quizz.species.forEach(sp => {