FaroServer
This commit is contained in:
parent
6f82430c3c
commit
cb54707d00
|
|
@ -121,12 +121,16 @@ async function cargarIntenciones() {
|
||||||
try {
|
try {
|
||||||
const response = await apiCall(endpoint);
|
const response = await apiCall(endpoint);
|
||||||
if (!response || !response.ok) {
|
if (!response || !response.ok) {
|
||||||
sinIntenciones.style.display = "block";
|
throw new Error("API no disponible");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const intenciones = await response.json();
|
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) {
|
if (intenciones.length === 0) {
|
||||||
sinIntenciones.style.display = "block";
|
sinIntenciones.style.display = "block";
|
||||||
return;
|
return;
|
||||||
|
|
@ -136,12 +140,13 @@ async function cargarIntenciones() {
|
||||||
intenciones.forEach(i => crearHexagono(i));
|
intenciones.forEach(i => crearHexagono(i));
|
||||||
|
|
||||||
} catch (e) {
|
} 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") {
|
if (ambitoActual === "personal") {
|
||||||
const local = JSON.parse(localStorage.getItem(keyIntenciones()) || localStorage.getItem("intenciones") || "[]");
|
const local = JSON.parse(localStorage.getItem(keyIntenciones()) || localStorage.getItem("intenciones") || "[]");
|
||||||
if (local.length === 0) {
|
if (local.length === 0) {
|
||||||
sinIntenciones.style.display = "block";
|
sinIntenciones.style.display = "block";
|
||||||
} else {
|
} else {
|
||||||
|
sinIntenciones.style.display = "none";
|
||||||
local.forEach(i => crearHexagono({ texto: i.texto, icono: i.icono, esPropia: true }));
|
local.forEach(i => crearHexagono({ texto: i.texto, icono: i.icono, esPropia: true }));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -171,6 +176,12 @@ async function guardarIntencion() {
|
||||||
|
|
||||||
if (response && response.ok) {
|
if (response && response.ok) {
|
||||||
const nueva = await response.json();
|
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 });
|
crearHexagono({ ...nueva, esPropia: true });
|
||||||
document.getElementById("sin-intenciones").style.display = "none";
|
document.getElementById("sin-intenciones").style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue