FaroServer
This commit is contained in:
parent
6f82430c3c
commit
cb54707d00
|
|
@ -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";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue