Files
NightSpire/web-next/app/[locale]/forum/create/[forumId]/page.tsx
T
2026-07-17 08:17:15 +00:00

70 lines
2.2 KiB
TypeScript

import { notFound, redirect } from 'next/navigation'
import { getTranslations, setRequestLocale } from 'next-intl/server'
import { getForum, getForumPath, getAccountCharactersForForum, getForumCharacterPick } from '@/lib/forum'
import { getSession } from '@/lib/session'
import { PageShell } from '@/components/PageShell'
import { ForumBreadcrumb } from '@/components/ForumBreadcrumb'
import { CreateTopicForm } from '@/components/CreateTopicForm'
import { ForumCharacterPicker } from '@/components/ForumCharacterPicker'
export const dynamic = 'force-dynamic'
export default async function CreateTopicPage({
params,
}: {
params: Promise<{ locale: string; forumId: string }>
}) {
const { locale, forumId } = await params
setRequestLocale(locale)
const t = await getTranslations('Forum')
const id = Number(forumId)
const forum = await getForum(id, locale)
if (!forum) notFound()
const session = await getSession()
if (!session.username) redirect(`/${locale}/forum/${id}`)
const [forumChars, forumPick] = session.accountId
? await Promise.all([getAccountCharactersForForum(session.accountId), getForumCharacterPick(session.accountId)])
: [[], null]
const path = await getForumPath(id, locale)
return (
<PageShell title={t('createTopic')}>
<div className="main-wide">
{path && (
<ForumBreadcrumb
items={[
{ label: t('title'), href: '/forum' },
{ label: path.forum, href: `/forum/${id}` },
{ label: t('createTopic') },
]}
/>
)}
<div className="forum_header create_header">
<div className="forum_title">
<h1>{forum.name}</h1>
{forum.description && <h3>{forum.description}</h3>}
</div>
</div>
<ForumCharacterPicker
locale={locale}
initialChars={forumChars}
initialCurrent={forumPick}
labels={{
postingAs: t('postingAs'),
change: t('changeCharacter'),
title: t('changeCharacter'),
filter: t('filter'),
empty: t('noCharacters'),
auto: t('autoCharacter'),
}}
/>
<CreateTopicForm forumId={id} />
</div>
</PageShell>
)
}