diff --git a/src/app/dashboard/media/page.tsx b/src/app/dashboard/media/page.tsx index 4ae4b2b..31fd215 100644 --- a/src/app/dashboard/media/page.tsx +++ b/src/app/dashboard/media/page.tsx @@ -9,11 +9,13 @@ import { Query } from 'node-appwrite'; export default async function MediaLibraryPage({ searchParams }: { - searchParams: { q?: string, page?: string } + searchParams: Promise<{ q?: string, page?: string, tipo?: string, orden?: string }> }) { const sParams = await searchParams; const q = sParams.q || ''; const page = Number(sParams.page) || 1; + const tipo = sParams.tipo || ''; + const orden = sParams.orden || 'desc'; const limit = 12; const offset = (page - 1) * limit; @@ -26,12 +28,16 @@ export default async function MediaLibraryPage({ const queries = [ Query.limit(limit), Query.offset(offset), - Query.orderDesc('$createdAt') + orden === 'asc' ? Query.orderAsc('$createdAt') : Query.orderDesc('$createdAt') ]; if (q) { queries.push(Query.contains('titulo', q)); } + + if (tipo === 'imagen' || tipo === 'video') { + queries.push(Query.equal('tipo', tipo)); + } const response = await sessionClient.databases.listDocuments( APPWRITE_ALMEIRA_CONFIG.databaseId, @@ -65,16 +71,28 @@ export default async function MediaLibraryPage({

-
- -
@@ -140,21 +158,33 @@ export default async function MediaLibraryPage({ {/* Pagination */} {total > limit && (
- - ANTERIOR - - - Página {page} de {Math.ceil(total / limit)} - - = Math.ceil(total / limit) ? 'opacity-30 pointer-events-none bg-slate-900' : 'bg-slate-900 text-white hover:border-pink-500'}`} - > - SIGUIENTE - + {(() => { + const currentParams = new URLSearchParams(); + if (q) currentParams.set('q', q); + if (tipo) currentParams.set('tipo', tipo); + if (orden !== 'desc') currentParams.set('orden', orden); + const baseQuery = currentParams.toString() ? `&${currentParams.toString()}` : ''; + + return ( + <> + + ANTERIOR + + + Página {page} de {Math.ceil(total / limit)} + + = Math.ceil(total / limit) ? 'opacity-30 pointer-events-none bg-slate-900' : 'bg-slate-900 text-white hover:border-pink-500'}`} + > + SIGUIENTE + + + ); + })()}
)}