Compare commits

..

No commits in common. "e4c630f2fa21772dd2df737196aa4b73230408ad" and "4ca6e72ab60a50351aacde3c48615f23aea12081" have entirely different histories.

3 changed files with 11 additions and 37 deletions

View File

@ -42,7 +42,6 @@ function inicializarVariables() {
fechaHoyElem = document.getElementById('fecha-hoy');
nombreCicloElem = document.getElementById('nombre_ciclo');
cicloParImparElem = document.getElementById('ciclo_par_impar');
santoDelDiaElem = document.getElementById('santo-del-dia');
descripcionSantoDelDiaElem = document.getElementById('descripcion-santo-del-dia');
indicadorLiturgicoElem = document.getElementById('indicador-liturgico');
}

View File

@ -137,20 +137,20 @@ async function difuntos() {
}
/* ================================
6. SANTO DEL DÍA
================================ */
async function santoDelDia() {
const hoy = new Date();
const offset = hoy.getTimezoneOffset() * 60000;
const fechaHoy = new Date(hoy - offset).toISOString().split('T')[0];
try {
const res = await apiCall('/santo/hoy');
const data = res && res.ok ? await res.json() : await cargarSantoLocal(fechaHoy);
if (!data) return;
if (!res || !res.ok) {
if (santoDelDiaElem) santoDelDiaElem.textContent = "";
if (descripcionSantoDelDiaElem) descripcionSantoDelDiaElem.textContent = "";
return;
}
const data = await res.json();
console.log("Actualizando santo:", data.santo, santoDelDiaElem, descripcionSantoDelDiaElem);
if (santoDelDiaElem) santoDelDiaElem.textContent = data.santo || "";
if (descripcionSantoDelDiaElem) descripcionSantoDelDiaElem.textContent = data.descripcion || "";
@ -158,21 +158,7 @@ async function santoDelDia() {
console.log("try: Actualizando santo:", data.santo, santoDelDiaElem);
} catch (e) {
console.error("Error obteniendo el santo del día desde la API:", e);
const data = await cargarSantoLocal(fechaHoy);
if (data && santoDelDiaElem) santoDelDiaElem.textContent = data.santo || "";
if (data && descripcionSantoDelDiaElem) descripcionSantoDelDiaElem.textContent = data.descripcion || "";
}
}
async function cargarSantoLocal(fecha) {
try {
const res = await fetch('data/santos.json');
if (!res.ok) throw new Error('No se pudo cargar el santoral local');
const santos = await res.json();
return santos.find(santo => santo.fecha === fecha) || null;
} catch (e) {
console.error("Error cargando el santoral local:", e);
return null;
console.log("catch: No se pudo actualizar el santo del día, manteniendo el texto actual:", santoDelDiaElem ? santoDelDiaElem.textContent : "Elemento no encontrado");
}
}

View File

@ -121,16 +121,12 @@ async function cargarIntenciones() {
try {
const response = await apiCall(endpoint);
if (!response || !response.ok) {
throw new Error("API no disponible");
sinIntenciones.style.display = "block";
return;
}
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;
@ -140,13 +136,12 @@ async function cargarIntenciones() {
intenciones.forEach(i => crearHexagono(i));
} catch (e) {
// Fallback a localStorage si la API falla o no hay conexión
// Si no hay conexión, mostrar las intenciones personales del localStorage como fallback
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 {
@ -176,12 +171,6 @@ 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";
}