From 54220a6c7ea4f966537adf17635a7f250fe314d5 Mon Sep 17 00:00:00 2001 From: "Carlos (Almeira)" Date: Sun, 21 Jun 2026 14:44:49 -0500 Subject: [PATCH] fix: Restrict month filter to admins only while keeping pagination public --- src/app/page.tsx | 73 ++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index d7a0726..42f5423 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -53,20 +53,19 @@ async function fetchHomeData(page: number = 1, isAdmin: boolean = false, adminMo if (isAdmin) { queries.push(Query.equal('estado', ['Publicado', 'borrador'])); + if (adminMonth) { + const currentYear = new Date().getFullYear(); + // First day of the selected month + const startDate = new Date(currentYear, adminMonth - 1, 1).toISOString(); + // First day of the next month + const endDate = new Date(currentYear, adminMonth, 1).toISOString(); + queries.push(Query.greaterThanEqual('fecha_publicacion', startDate)); + queries.push(Query.lessThan('fecha_publicacion', endDate)); + } } else { queries.push(Query.equal('estado', 'Publicado')); } - if (adminMonth) { - const currentYear = new Date().getFullYear(); - // First day of the selected month - const startDate = new Date(currentYear, adminMonth - 1, 1).toISOString(); - // First day of the next month - const endDate = new Date(currentYear, adminMonth, 1).toISOString(); - queries.push(Query.greaterThanEqual('fecha_publicacion', startDate)); - queries.push(Query.lessThan('fecha_publicacion', endDate)); - } - const postsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'posts', queries); posts = postsRes.documents as unknown as Post[]; totalPages = Math.ceil(postsRes.total / postsCount); @@ -158,32 +157,34 @@ export default async function Home(props: { searchParams: Promise<{ [key: string

Feed de Noticias

-
- - Mes: - - -
+ {isAdmin && ( +
+ + Filtro Admin: + + +
+ )} {posts.length === 0 ? (