From cb54707d00db87d1aa0a050a9537a885512d6f26 Mon Sep 17 00:00:00 2001 From: Tatiana Villa Date: Sat, 5 Sep 2026 11:32:08 +0200 Subject: [PATCH] FaroServer --- frontend/js/intenciones.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/js/intenciones.js b/frontend/js/intenciones.js index f2c180b..8bcb904 100644 --- a/frontend/js/intenciones.js +++ b/frontend/js/intenciones.js @@ -121,12 +121,16 @@ async function cargarIntenciones() { try { const response = await apiCall(endpoint); if (!response || !response.ok) { - sinIntenciones.style.display = "block"; - return; + throw new Error("API no disponible"); } const intenciones = await response.json(); + // Actualizar caché local con los datos de la API + if (ambitoActual === "personal") { + localStorage.setItem(keyIntenciones(), JSON.stringify(intenciones)); + } + if (intenciones.length === 0) { sinIntenciones.style.display = "block"; return; @@ -136,12 +140,13 @@ async function cargarIntenciones() { intenciones.forEach(i => crearHexagono(i)); } catch (e) { - // Si no hay conexión, mostrar las intenciones personales del localStorage como fallback + // Fallback a localStorage si la API falla o no hay conexión if (ambitoActual === "personal") { const local = JSON.parse(localStorage.getItem(keyIntenciones()) || localStorage.getItem("intenciones") || "[]"); if (local.length === 0) { sinIntenciones.style.display = "block"; } else { + sinIntenciones.style.display = "none"; local.forEach(i => crearHexagono({ texto: i.texto, icono: i.icono, esPropia: true })); } } else { @@ -171,6 +176,12 @@ async function guardarIntencion() { if (response && response.ok) { const nueva = await response.json(); + // Actualizar caché local + if (ambitoActual === "personal") { + const local = JSON.parse(localStorage.getItem(keyIntenciones()) || "[]"); + local.push(nueva); + localStorage.setItem(keyIntenciones(), JSON.stringify(local)); + } crearHexagono({ ...nueva, esPropia: true }); document.getElementById("sin-intenciones").style.display = "none"; }