almeira-web/src/app/page.tsx

143 lines
7.9 KiB
TypeScript

import { APPWRITE_ALMEIRA_CONFIG } from '@/lib/appwrite';
import { createAdminClient } from '@/lib/appwrite.server';
import { Query } from 'node-appwrite';
import { NewsCard } from '@/components/NewsCard';
import { GlobalSidebar } from '@/components/AdWrappers';
import { RadioTower, Sparkles, ChevronDown, Loader2 } from 'lucide-react';
import { Suspense } from 'react';
async function fetchHomeData() {
try {
const client = await createAdminClient();
// 1. Settings for count
const settingsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', []);
const postsCount = settingsRes.documents.length > 0 ? (settingsRes.documents[0].feed_count || settingsRes.documents[0].post_count || 9) : 9;
// 2. Get NOTICIA type ID
const typeRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'publication_types', [
Query.equal('codigo', 'NOTICIA')
]);
let posts: any[] = [];
if (typeRes.documents.length > 0) {
const typeId = typeRes.documents[0].$id;
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)
]);
posts = postsRes.documents;
}
return { posts };
} catch (e) {
console.error("Home fetch error", e);
return { posts: [] };
}
}
export default async function Home() {
const { posts } = await fetchHomeData();
return (
<main className="animate-fade-in relative">
{/* Sci-Fi Hero Section */}
<section className="relative flex flex-col items-center justify-center min-h-screen text-center px-4 overflow-hidden mesh-bg">
{/* Dynamic Orbs background */}
<div className="absolute top-1/4 left-1/4 w-[500px] h-[500px] bg-cyan-500/20 rounded-full blur-[120px] mix-blend-screen pointer-events-none animate-pulse"></div>
<div className="absolute bottom-1/4 right-1/4 w-[600px] h-[600px] bg-purple-600/20 rounded-full blur-[150px] mix-blend-screen pointer-events-none animate-float"></div>
<div className="relative z-10 flex flex-col items-center max-w-5xl mx-auto">
<div className="inline-flex items-center gap-2 px-4 py-2 border border-cyan-500/30 rounded-full bg-cyan-500/10 text-cyan-300 text-sm font-semibold mb-8 animate-float shadow-[0_0_20px_rgba(6,182,212,0.2)] backdrop-blur-md">
<RadioTower size={16} className="animate-pulse" />
<span className="tracking-widest uppercase">Señal En Vivo 24/7</span>
</div>
<h1 className="text-6xl md:text-8xl font-outfit font-black tracking-tighter mb-6 leading-[1.1]">
NOTICIAS AL <br/>
<span className="holographic-text block mt-2">SIGUIENTE NIVEL</span>
</h1>
<p className="text-lg md:text-xl text-slate-400 max-w-2xl mb-12 font-medium leading-relaxed">
El primer portal transaccional hiperconectado. Sumérgete en la actualidad de la región en tiempo real con una interfaz sin precedentes.
</p>
<a
href="#noticias"
className="group relative inline-flex items-center justify-center gap-3 px-8 py-4 rounded-full font-bold text-white text-lg overflow-hidden transition-all hover:scale-105"
>
<div className="absolute inset-0 bg-gradient-to-r from-cyan-500 to-blue-600 opacity-90 group-hover:opacity-100 transition-opacity"></div>
<div className="absolute -inset-1 bg-cyan-400 blur-xl opacity-40 group-hover:opacity-70 transition-opacity rounded-full animate-pulse"></div>
<Sparkles size={20} className="relative z-10" />
<span className="relative z-10 tracking-wide">EXPLORAR CONTENIDO</span>
</a>
</div>
{/* Scroll Indicator */}
<a href="#noticias" className="absolute bottom-10 left-1/2 -translate-x-1/2 flex flex-col items-center gap-2 text-slate-500 animate-bounce cursor-pointer hover:text-cyan-400 transition-colors">
<span className="text-xs font-bold uppercase tracking-widest">Descubrir</span>
<ChevronDown size={24} className="text-cyan-500" />
</a>
</section>
{/* Feed Section */}
<section id="noticias" className="container mx-auto px-4 py-24 relative z-10 w-full">
<div className="flex flex-col lg:flex-row gap-8 w-full items-start">
<div className="flex-1 w-full relative">
<div className="flex flex-col md:flex-row justify-between items-end mb-12 gap-6">
<div>
<div className="flex items-center gap-3 mb-2">
<div className="w-12 h-1 bg-gradient-to-r from-cyan-400 to-blue-600 rounded-full"></div>
<span className="text-cyan-400 font-bold tracking-widest uppercase text-sm">Último Minuto</span>
</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>
</div>
{posts.length === 0 ? (
<div className="w-full py-32 flex flex-col items-center justify-center border border-white/5 rounded-3xl glass-panel relative overflow-hidden">
<div className="absolute inset-0 bg-gradient-to-b from-cyan-500/5 to-transparent"></div>
<div className="p-6 rounded-full bg-slate-800/80 mb-6 border border-white/10 shadow-[0_0_40px_rgba(6,182,212,0.15)] relative z-10">
<RadioTower size={48} className="text-cyan-500" />
</div>
<h3 className="text-2xl font-black font-outfit text-white mb-2 relative z-10">Sin Conexión Reciente</h3>
<p className="text-slate-400 relative z-10">El portal se encuentra a la espera de señales desde el núcleo central.</p>
</div>
) : (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-3 gap-6">
{posts.map((post) => {
const PROJECT_ID = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c';
const ENDPOINT = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1';
let imagenUrl = null;
if (post.imagen_destacada_id) {
imagenUrl = `${ENDPOINT}/storage/buckets/${post.imagen_destacada_id.bucket_id}/files/${post.imagen_destacada_id.file_id}/preview?project=${PROJECT_ID}&width=800&height=500&quality=85`;
}
return (
<NewsCard
key={post.$id}
id={post.$id}
slug={post.slug || post.$id}
titulo={post.titulo}
resumen={post.resumen_redes || post.contenido?.substring(0, 100).replace(/<[^>]*>?/gm, '') + '...'}
tipo="Noticia"
fecha={post.fecha_publicacion || post.$createdAt}
imagenUrl={imagenUrl}
/>
)
})}
</div>
)}
</div>
<aside className="w-full lg:w-[320px] xl:w-[360px] shrink-0 mt-8 lg:mt-0 sticky top-24">
<GlobalSidebar />
</aside>
</div>
</section>
</main>
);
}