feat: Allow all users to see and use month filter on the news feed
This commit is contained in:
parent
0d110dae11
commit
08c5cdbe18
@ -53,19 +53,20 @@ 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);
|
||||
@ -157,34 +158,32 @@ export default async function Home(props: { searchParams: Promise<{ [key: string
|
||||
</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>
|
||||
</div>
|
||||
{isAdmin && (
|
||||
<form action="/" method="GET" className="flex items-center gap-3 bg-slate-800/80 p-3 rounded-xl border border-white/10">
|
||||
<input type="hidden" name="page" value="1" />
|
||||
<span className="text-sm text-slate-400 font-bold uppercase tracking-wider">Filtro Admin:</span>
|
||||
<select
|
||||
name="month"
|
||||
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="2">Febrero</option>
|
||||
<option value="3">Marzo</option>
|
||||
<option value="4">Abril</option>
|
||||
<option value="5">Mayo</option>
|
||||
<option value="6">Junio</option>
|
||||
<option value="7">Julio</option>
|
||||
<option value="8">Agosto</option>
|
||||
<option value="9">Septiembre</option>
|
||||
<option value="10">Octubre</option>
|
||||
<option value="11">Noviembre</option>
|
||||
<option value="12">Diciembre</option>
|
||||
</select>
|
||||
<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">
|
||||
Filtrar
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
<form action="/" method="GET" className="flex items-center gap-3 bg-slate-800/80 p-3 rounded-xl border border-white/10">
|
||||
<input type="hidden" name="page" value="1" />
|
||||
<span className="text-sm text-slate-400 font-bold uppercase tracking-wider">Mes:</span>
|
||||
<select
|
||||
name="month"
|
||||
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="2">Febrero</option>
|
||||
<option value="3">Marzo</option>
|
||||
<option value="4">Abril</option>
|
||||
<option value="5">Mayo</option>
|
||||
<option value="6">Junio</option>
|
||||
<option value="7">Julio</option>
|
||||
<option value="8">Agosto</option>
|
||||
<option value="9">Septiembre</option>
|
||||
<option value="10">Octubre</option>
|
||||
<option value="11">Noviembre</option>
|
||||
<option value="12">Diciembre</option>
|
||||
</select>
|
||||
<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">
|
||||
Filtrar
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{posts.length === 0 ? (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user