import { notFound } from 'next/navigation' import { getTranslations, setRequestLocale } from 'next-intl/server' import { Link } from '@/i18n/navigation' import { getForum, getTopics, countTopics } from '@/lib/forum' import { getSession } from '@/lib/session' import { NewTopicForm } from '@/components/NewTopicForm' import { Pagination } from '@/components/Pagination' export const dynamic = 'force-dynamic' const PER_PAGE = 20 export default async function ForumPage({ params, searchParams, }: { params: Promise<{ locale: string; forumId: string }> searchParams: Promise<{ page?: string }> }) { const { locale, forumId } = await params setRequestLocale(locale) const t = await getTranslations('Forum') const id = Number(forumId) const forum = await getForum(id) if (!forum) notFound() const total = await countTopics(id) const totalPages = Math.max(1, Math.ceil(total / PER_PAGE)) const page = Math.min(Math.max(1, Number((await searchParams).page) || 1), totalPages) const topics = await getTopics(id, (page - 1) * PER_PAGE, PER_PAGE) const session = await getSession() const canPost = Boolean(session.username) return (

← {t('backToForum')}

{forum!.name}

{forum!.description &&

{forum!.description}

} {topics.length === 0 ? (

{t('noTopics')}

) : ( )} `/forum/${id}?page=${p}`} /> {canPost ? ( ) : (

{t('loginToPost')}

)}
) }