Compare commits

...

3 Commits

Author SHA1 Message Date
Tatiana Villa e4c630f2fa Arreglando el santo del dia 2026-09-05 12:06:09 +02:00
Tatiana Villa acf7b9e458 Merge branch 'main' of https://git.tatvil.es/tatiana/recursos-catolicos 2026-09-05 11:32:58 +02:00
Tatiana Villa cb54707d00 FaroServer 2026-09-05 11:32:08 +02:00
3 changed files with 37 additions and 11 deletions

View File

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

View File

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

View File

@ -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";
} }