diff --git a/almeira-web-deploy.zip b/almeira-web-deploy.zip index dab8333..77025b7 100644 Binary files a/almeira-web-deploy.zip and b/almeira-web-deploy.zip differ diff --git a/src/app/page.tsx b/src/app/page.tsx index 91943b4..b736cbc 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -9,7 +9,7 @@ import { decodeHtmlEntities } from '@/lib/utils'; import { Settings } from '@/types/settings'; import { Post, MediaItem } from '@/types/publications'; -async function fetchHomeData() { +async function fetchHomeData(page: number = 1) { try { const client = await createAdminClient(); @@ -36,17 +36,22 @@ async function fetchHomeData() { ]); let posts: Post[] = []; + let totalPages = 1; if (typeRes.documents.length > 0) { const firstType = typeRes.documents[0]; const typeId = firstType?.$id; - if (!typeId) return { posts: [], cardSettings }; + if (!typeId) return { posts: [], cardSettings, totalPages: 1 }; + + const offset = (page - 1) * postsCount; const postsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'posts', [ Query.equal('tipo_publicacion_id', typeId), Query.equal('estado', 'Publicado'), Query.orderDesc('fecha_publicacion'), - Query.limit(postsCount) + Query.limit(postsCount), + Query.offset(offset) ]); posts = postsRes.documents as unknown as Post[]; + totalPages = Math.ceil(postsRes.total / postsCount); // 3. Resolve Media const mediaIds = posts.map(p => p.imagen_destacada_id).filter(id => id && typeof id === 'string'); @@ -62,17 +67,19 @@ async function fetchHomeData() { } } - return { posts, cardSettings }; + return { posts, cardSettings, totalPages }; } catch (e) { console.error("Home fetch error", e); - return { posts: [], cardSettings: { showCategory: false, showFooterDate: true, showFooterButton: true, footerText: "" } }; + return { posts: [], cardSettings: { showCategory: false, showFooterDate: true, showFooterButton: true, footerText: "" }, totalPages: 1 }; } } export const dynamic = "force-dynamic"; -export default async function Home() { - const { posts, cardSettings } = await fetchHomeData(); +export default async function Home(props: { searchParams: Promise<{ [key: string]: string | string[] | undefined }> }) { + const searchParams = await props.searchParams; + const page = Number(searchParams?.page) || 1; + const { posts, cardSettings, totalPages } = await fetchHomeData(page); const hasSidebar = await hasSidebarContent(); const user = await getLoggedInUser(); @@ -173,6 +180,31 @@ export default async function Home() { })} )} + + {/* Pagination Controls */} + {totalPages > 1 && ( +