import { getTranslations, setRequestLocale } from 'next-intl/server' import { Link } from '@/i18n/navigation' import { getForumIndex, resolvePosters, type ForumRow } from '@/lib/forum' import { formatForumDate } from '@/lib/forum-format' import { PageShell } from '@/components/PageShell' export const dynamic = 'force-dynamic' export default async function ForumIndexPage({ params }: { params: Promise<{ locale: string }> }) { const { locale } = await params setRequestLocale(locale) const t = await getTranslations('Forum') const categories = await getForumIndex(locale) // Nombres de los Ășltimos posteadores de todos los foros, en una sola consulta. const posterIds = categories.flatMap((c) => c.forums.map((f) => f.last_poster).filter(Boolean) as number[]) const posters = await resolvePosters(posterIds) function topicsLabel(n: number) { return `${n} ${n === 1 ? t('topic') : t('topics')}` } function NormalRow({ f }: { f: ForumRow }) { const iconSrc = f.type === 3 ? f.icon || '' : `/forum/forum_icons/${f.icon || 'forum_read'}.png` return (
{f.post_count}
{f.topic_count}
{f.last_topic_name}
{f.last_poster != null && ({posters.get(f.last_poster)?.name ?? `#${f.last_poster}`}
)}{formatForumDate(f.last_time, locale)}
{t('noForums')}
) : ( categories.map((cat) => { const tiles = cat.forums.filter((f) => f.type === 1 || f.type === 2) const rows = cat.forums.filter((f) => f.type !== 1 && f.type !== 2) return (