Skip to content

Commit c5d775f

Browse files
committed
fixe bug about lecciones array being empty
1 parent a0e784e commit c5d775f

File tree

2 files changed

+9
-166
lines changed

2 files changed

+9
-166
lines changed

package-lock.json

Lines changed: 0 additions & 162 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/main.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {} from 'sweetalert';
22
import json from '../config/config.json';
33

44
window.onload = () => loadPage();
5+
var lecciones = [];
56

67
function loadPage() {
78

@@ -15,9 +16,9 @@ function loadPage() {
1516
}
1617

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

20-
var lecciones = json.lecciones[lang];
21+
lecciones = json.lecciones[lang];
2122
var config = json.config;
2223
var leccionActual = 1;
2324
var leccionesTotal = getObjLength(lecciones);
@@ -41,6 +42,10 @@ function loadPage() {
4142
// Cambiar lenguaje
4243
const langSwitch = document.querySelector('#lang');
4344
langSwitch.addEventListener('change', () => {
45+
46+
// avoid switching to invalid languages
47+
if(!['en', 'es', 'us'].includes(langSwitch.value)) return;
48+
4449
lang = langSwitch.value;
4550
lecciones = json.lecciones[lang];
4651

@@ -82,7 +87,7 @@ function loadPage() {
8287
});
8388

8489
// Inicializar con el lenguaje de la query string
85-
const initialLang = getQueryParam('lang') || 'defaultLang';
90+
const initialLang = getQueryParam('lang') || 'en';
8691
langSwitch.value = initialLang;
8792
langSwitch.dispatchEvent(new Event('change'));
8893

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

0 commit comments

Comments
 (0)