Compare commits
No commits in common. "e4c630f2fa21772dd2df737196aa4b73230408ad" and "4ca6e72ab60a50351aacde3c48615f23aea12081" have entirely different histories.
e4c630f2fa
...
4ca6e72ab6
|
|
@ -42,7 +42,6 @@ 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');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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');
|
||||||
const data = res && res.ok ? await res.json() : await cargarSantoLocal(fechaHoy);
|
if (!res || !res.ok) {
|
||||||
|
if (santoDelDiaElem) santoDelDiaElem.textContent = "";
|
||||||
if (!data) return;
|
if (descripcionSantoDelDiaElem) descripcionSantoDelDiaElem.textContent = "";
|
||||||
|
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,21 +158,7 @@ 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);
|
||||||
const data = await cargarSantoLocal(fechaHoy);
|
console.log("catch: No se pudo actualizar el santo del día, manteniendo el texto actual:", santoDelDiaElem ? santoDelDiaElem.textContent : "Elemento no encontrado");
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,16 +121,12 @@ async function cargarIntenciones() {
|
||||||
try {
|
try {
|
||||||
const response = await apiCall(endpoint);
|
const response = await apiCall(endpoint);
|
||||||
if (!response || !response.ok) {
|
if (!response || !response.ok) {
|
||||||
throw new Error("API no disponible");
|
sinIntenciones.style.display = "block";
|
||||||
|
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;
|
||||||
|
|
@ -140,13 +136,12 @@ async function cargarIntenciones() {
|
||||||
intenciones.forEach(i => crearHexagono(i));
|
intenciones.forEach(i => crearHexagono(i));
|
||||||
|
|
||||||
} catch (e) {
|
} 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") {
|
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 {
|
||||||
|
|
@ -176,12 +171,6 @@ 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