Skip to content

Commit

Permalink
fixe bug about lecciones array being empty
Browse files Browse the repository at this point in the history
  • Loading branch information
alesanchezr committed Jan 7, 2025
1 parent a0e784e commit c5d775f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 166 deletions.
162 changes: 0 additions & 162 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {} from 'sweetalert';
import json from '../config/config.json';

window.onload = () => loadPage();
var lecciones = [];

function loadPage() {

Expand All @@ -15,9 +16,9 @@ function loadPage() {
}

let lang = getQueryParam('lang') || document.querySelector('#lang').value || 'defaultLang';
console.log(`Language selected: ${lang}`);
console.log(`Language selected: ${lang}`, json);

var lecciones = json.lecciones[lang];
lecciones = json.lecciones[lang];
var config = json.config;
var leccionActual = 1;
var leccionesTotal = getObjLength(lecciones);
Expand All @@ -41,6 +42,10 @@ function loadPage() {
// Cambiar lenguaje
const langSwitch = document.querySelector('#lang');
langSwitch.addEventListener('change', () => {

// avoid switching to invalid languages
if(!['en', 'es', 'us'].includes(langSwitch.value)) return;

lang = langSwitch.value;
lecciones = json.lecciones[lang];

Expand Down Expand Up @@ -82,7 +87,7 @@ function loadPage() {
});

// Inicializar con el lenguaje de la query string
const initialLang = getQueryParam('lang') || 'defaultLang';
const initialLang = getQueryParam('lang') || 'en';
langSwitch.value = initialLang;
langSwitch.dispatchEvent(new Event('change'));

Expand All @@ -95,7 +100,7 @@ function loadPage() {
// ==================================================
// Updates every contentn area in the site
function actualizarInfoLeccion() {
if (!lecciones[leccionActual]) {
if (!lecciones || !lecciones[leccionActual]) {
console.error(`Lección ${leccionActual} no encontrada en el lenguaje ${lang}`);
return;
}
Expand Down

0 comments on commit c5d775f

Please sign in to comment.