import { notFound } from 'next/navigation' import { getTranslations, setRequestLocale } from 'next-intl/server' import { Link } from '@/i18n/navigation' import { getTopic, getPosts, countPosts, listForumsForMove } from '@/lib/forum' import { getSession } from '@/lib/session' import { forumIsModerator, canEditPost } from '@/lib/forum-perm' import { PageShell } from '@/components/PageShell' import { ReplyForm } from '@/components/ReplyForm' import { PostActions } from '@/components/PostActions' import { TopicModBar } from '@/components/TopicModBar' import { Pagination } from '@/components/Pagination' export const dynamic = 'force-dynamic' const PER_PAGE = 15 export default async function TopicPage({ params, searchParams, }: { params: Promise<{ locale: string; topicId: string }> searchParams: Promise<{ page?: string }> }) { const { locale, topicId } = await params setRequestLocale(locale) const t = await getTranslations('Forum') const id = Number(topicId) const session = await getSession() const isMod = await forumIsModerator(session) const topic = await getTopic(id, isMod) if (!topic) notFound() const total = await countPosts(id, isMod) const totalPages = Math.max(1, Math.ceil(total / PER_PAGE)) const page = Math.min(Math.max(1, Number((await searchParams).page) || 1), totalPages) const posts = await getPosts(id, (page - 1) * PER_PAGE, PER_PAGE, isMod) const moveForums = isMod ? (await listForumsForMove()).filter((f) => f.id !== topic!.forum_id) : [] const canReply = Boolean(session.username) && (!topic!.locked || isMod) const title = ( <> {topic!.sticky && [{t('pinned')}] } {topic!.locked && [{t('locked')}] } {topic!.deleted && [{t('deletedMark')}] } {topic!.name} > ) return ( ← {t('backToForum')} {isMod && ( )} {posts.map((post) => ( {post.poster} {post.deleted && [{t('deletedMark')}]} {post.time && ( {new Date(post.time).toLocaleString(locale)} {post.edited && · {t('editedMark')}} )} {canEditPost(session, isMod, post.poster_id) && ( )} ))} `/forum/topic/${id}?page=${p}`} /> {canReply ? ( page === totalPages ? ( ) : ( {t('replyOnLastPage')} ) ) : ( !session.username && {t('loginToPost')} )} ) }
← {t('backToForum')}
{t('replyOnLastPage')}
{t('loginToPost')}