diff --git a/agenda.html b/agenda.html index ce667e1..a4d399f 100644 --- a/agenda.html +++ b/agenda.html @@ -122,7 +122,35 @@

Cargando...

+
+
+
+ +
+
+

Filtrar por Mes

+

Busca bloqueos pasados o futuros

+
+
+
+ + +
+
+

+ Bloqueos Activos a Futuro +

+
+

Cargando...

+
+ +

+ Historial Pasado +

+
+

Cargando...

+
@@ -374,6 +402,9 @@ const activeContainer = document.getElementById('blocksList'); const pastContainer = document.getElementById('pastBlocksList'); + // Leemos el valor del filtro de mes (Ej: "2026-02") + const monthFilter = document.getElementById('blockMonthFilter').value; + try { const res = await fetch(`${API_URL}/agenda/blocks`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } @@ -382,25 +413,30 @@ if (!data.ok) throw new Error("Error fetching blocks"); + let allBlocks = data.blocks; + + // 🧠 APLICAMOS EL FILTRO POR MES SI HAY ALGUNO SELECCIONADO + if (monthFilter) { + // Nos quedamos solo con los bloqueos cuya fecha empiece por "YYYY-MM" + allBlocks = allBlocks.filter(b => b.date.startsWith(monthFilter)); + } + // Sacamos la fecha de hoy (YYYY-MM-DD) para comparar const todayStr = new Date().toISOString().split('T')[0]; - // El servidor los manda de más reciente a más antiguo (DESC). - // Los activos los queremos al revés (ASC: el próximo primero) - const activeBlocks = data.blocks.filter(b => b.date >= todayStr).reverse(); - // Los pasados los dejamos en DESC (el más reciente caducado arriba) - const pastBlocks = data.blocks.filter(b => b.date < todayStr); + const activeBlocks = allBlocks.filter(b => b.date >= todayStr).reverse(); + const pastBlocks = allBlocks.filter(b => b.date < todayStr); // Pintar Activos if (activeBlocks.length === 0) { - activeContainer.innerHTML = `

No hay bloqueos activos a futuro.

`; + activeContainer.innerHTML = `

No hay bloqueos activos en este periodo.

`; } else { activeContainer.innerHTML = activeBlocks.map(b => buildBlockHtml(b, false)).join(''); } // Pintar Caducados if (pastBlocks.length === 0) { - pastContainer.innerHTML = `

No hay bloqueos antiguos.

`; + pastContainer.innerHTML = `

No hay bloqueos antiguos en este periodo.

`; } else { pastContainer.innerHTML = pastBlocks.map(b => buildBlockHtml(b, true)).join(''); }