fix: Hoy carga siempre datos de hoy independiente del mes seleccionado
This commit is contained in:
parent
bb141390f2
commit
d14be12029
|
|
@ -41,14 +41,13 @@ async function loadStats(options = {}) {
|
|||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error("Error cargando datos: " + response.status);
|
||||
|
||||
let data = await response.json(); // Cambia 'const' por 'let'
|
||||
let data = await response.json();
|
||||
if (!data || !data.length) throw new Error("Datos vacíos");
|
||||
|
||||
// --- FILTRADO POR CIUDAD (Importante mientras Java no filtre) ---
|
||||
// --- FILTRADO POR CIUDAD ---
|
||||
data = data.filter(d => d.ciudad === ciudadActual);
|
||||
// ----------------------------------------------------------------
|
||||
// ---------------------------
|
||||
|
||||
renderLastData(data);
|
||||
renderMonthStats(data);
|
||||
renderTrend(data);
|
||||
|
||||
|
|
@ -58,6 +57,29 @@ async function loadStats(options = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
async function loadToday() {
|
||||
try {
|
||||
const ahora = new Date();
|
||||
const y = ahora.getFullYear();
|
||||
const m = String(ahora.getMonth() + 1).padStart(2, "0");
|
||||
const d = String(ahora.getDate()).padStart(2, "0");
|
||||
const hoy = `${y}-${m}-${d}`;
|
||||
|
||||
const url = buildApiUrl({ ciudad: ciudadActual, desde: hoy, hasta: hoy });
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error("Error cargando hoy: " + response.status);
|
||||
|
||||
let data = await response.json();
|
||||
if (!data || !data.length) throw new Error("Sin datos de hoy");
|
||||
|
||||
data = data.filter(d => d.ciudad === ciudadActual);
|
||||
renderLastData(data);
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// ====================
|
||||
// Último dato
|
||||
// ====================
|
||||
|
|
@ -256,6 +278,7 @@ function loadCurrentMonth() {
|
|||
document.addEventListener("DOMContentLoaded", () => {
|
||||
updateMonthHeader();
|
||||
getMoonPhase();
|
||||
loadToday();
|
||||
loadCurrentMonth();
|
||||
|
||||
$("prev-month").addEventListener("click", () => {
|
||||
|
|
@ -277,6 +300,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
// ====================
|
||||
$("city-select").addEventListener("change", (e) => {
|
||||
ciudadActual = e.target.value;
|
||||
loadToday();
|
||||
loadCurrentMonth();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue