fix: Restrict month filter to admins only while keeping pagination public
This commit is contained in:
parent
08c5cdbe18
commit
54220a6c7e
@ -53,20 +53,19 @@ async function fetchHomeData(page: number = 1, isAdmin: boolean = false, adminMo
|
|||||||
|
|
||||||
if (isAdmin) {
|
if (isAdmin) {
|
||||||
queries.push(Query.equal('estado', ['Publicado', 'borrador']));
|
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 {
|
} else {
|
||||||
queries.push(Query.equal('estado', 'Publicado'));
|
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);
|
const postsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'posts', queries);
|
||||||
posts = postsRes.documents as unknown as Post[];
|
posts = postsRes.documents as unknown as Post[];
|
||||||
totalPages = Math.ceil(postsRes.total / postsCount);
|
totalPages = Math.ceil(postsRes.total / postsCount);
|
||||||
@ -158,32 +157,34 @@ export default async function Home(props: { searchParams: Promise<{ [key: string
|
|||||||
</div>
|
</div>
|
||||||
<h2 className="text-4xl md:text-5xl font-outfit font-black text-white">Feed de <span className="text-transparent bg-clip-text bg-gradient-to-r from-white to-slate-500">Noticias</span></h2>
|
<h2 className="text-4xl md:text-5xl font-outfit font-black text-white">Feed de <span className="text-transparent bg-clip-text bg-gradient-to-r from-white to-slate-500">Noticias</span></h2>
|
||||||
</div>
|
</div>
|
||||||
<form action="/" method="GET" className="flex items-center gap-3 bg-slate-800/80 p-3 rounded-xl border border-white/10">
|
{isAdmin && (
|
||||||
<input type="hidden" name="page" value="1" />
|
<form action="/" method="GET" className="flex items-center gap-3 bg-slate-800/80 p-3 rounded-xl border border-white/10">
|
||||||
<span className="text-sm text-slate-400 font-bold uppercase tracking-wider">Mes:</span>
|
<input type="hidden" name="page" value="1" />
|
||||||
<select
|
<span className="text-sm text-slate-400 font-bold uppercase tracking-wider">Filtro Admin:</span>
|
||||||
name="month"
|
<select
|
||||||
className="bg-slate-900 border border-white/10 text-white rounded-lg px-3 py-2 text-sm outline-none focus:border-cyan-500"
|
name="month"
|
||||||
defaultValue={adminMonth || ""}
|
className="bg-slate-900 border border-white/10 text-white rounded-lg px-3 py-2 text-sm outline-none focus:border-cyan-500"
|
||||||
>
|
defaultValue={adminMonth || ""}
|
||||||
<option value="">Todos los meses</option>
|
>
|
||||||
<option value="1">Enero</option>
|
<option value="">Todos los meses</option>
|
||||||
<option value="2">Febrero</option>
|
<option value="1">Enero</option>
|
||||||
<option value="3">Marzo</option>
|
<option value="2">Febrero</option>
|
||||||
<option value="4">Abril</option>
|
<option value="3">Marzo</option>
|
||||||
<option value="5">Mayo</option>
|
<option value="4">Abril</option>
|
||||||
<option value="6">Junio</option>
|
<option value="5">Mayo</option>
|
||||||
<option value="7">Julio</option>
|
<option value="6">Junio</option>
|
||||||
<option value="8">Agosto</option>
|
<option value="7">Julio</option>
|
||||||
<option value="9">Septiembre</option>
|
<option value="8">Agosto</option>
|
||||||
<option value="10">Octubre</option>
|
<option value="9">Septiembre</option>
|
||||||
<option value="11">Noviembre</option>
|
<option value="10">Octubre</option>
|
||||||
<option value="12">Diciembre</option>
|
<option value="11">Noviembre</option>
|
||||||
</select>
|
<option value="12">Diciembre</option>
|
||||||
<button type="submit" className="bg-cyan-600 hover:bg-cyan-500 text-white font-bold px-4 py-2 rounded-lg text-sm transition-colors">
|
</select>
|
||||||
Filtrar
|
<button type="submit" className="bg-cyan-600 hover:bg-cyan-500 text-white font-bold px-4 py-2 rounded-lg text-sm transition-colors">
|
||||||
</button>
|
Filtrar
|
||||||
</form>
|
</button>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{posts.length === 0 ? (
|
{posts.length === 0 ? (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user