feat: Allow all users to see and use month filter on the news feed
This commit is contained in:
parent
0d110dae11
commit
08c5cdbe18
@ -53,6 +53,10 @@ 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']));
|
||||||
|
} else {
|
||||||
|
queries.push(Query.equal('estado', 'Publicado'));
|
||||||
|
}
|
||||||
|
|
||||||
if (adminMonth) {
|
if (adminMonth) {
|
||||||
const currentYear = new Date().getFullYear();
|
const currentYear = new Date().getFullYear();
|
||||||
// First day of the selected month
|
// First day of the selected month
|
||||||
@ -62,9 +66,6 @@ async function fetchHomeData(page: number = 1, isAdmin: boolean = false, adminMo
|
|||||||
queries.push(Query.greaterThanEqual('fecha_publicacion', startDate));
|
queries.push(Query.greaterThanEqual('fecha_publicacion', startDate));
|
||||||
queries.push(Query.lessThan('fecha_publicacion', endDate));
|
queries.push(Query.lessThan('fecha_publicacion', endDate));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
queries.push(Query.equal('estado', 'Publicado'));
|
|
||||||
}
|
|
||||||
|
|
||||||
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[];
|
||||||
@ -157,10 +158,9 @@ 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>
|
||||||
{isAdmin && (
|
|
||||||
<form action="/" method="GET" className="flex items-center gap-3 bg-slate-800/80 p-3 rounded-xl border border-white/10">
|
<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" />
|
<input type="hidden" name="page" value="1" />
|
||||||
<span className="text-sm text-slate-400 font-bold uppercase tracking-wider">Filtro Admin:</span>
|
<span className="text-sm text-slate-400 font-bold uppercase tracking-wider">Mes:</span>
|
||||||
<select
|
<select
|
||||||
name="month"
|
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"
|
className="bg-slate-900 border border-white/10 text-white rounded-lg px-3 py-2 text-sm outline-none focus:border-cyan-500"
|
||||||
@ -184,7 +184,6 @@ export default async function Home(props: { searchParams: Promise<{ [key: string
|
|||||||
Filtrar
|
Filtrar
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{posts.length === 0 ? (
|
{posts.length === 0 ? (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user