import Link from 'next/link' import { notFound } from 'next/navigation' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { Pin, Lock } from 'lucide-react' import { createClient } from '@/lib/supabase/server' import { CommentThread } from '@/components/comments/comment-thread' import { loadComments } from '@/components/comments/load-comments' import { ThreadActions } from './thread-actions' export default async function ForumThreadPage({ params }: { params: Promise<{ id: string }> }) { const { id } = await params const supabase = await createClient() const { data: { user } } = await supabase.auth.getUser() if (!user) return null const { data: self } = await supabase .from('space_members') .select('id, space_id, role, display_name') .eq('user_id', user.id) .in('status', ['current', 'unverified', 'late']) .single() if (!self) return null const { data: thread } = await supabase .from('forum_threads') .select('id, title, body, category, pinned, locked, comment_count, created_at, author_id, space_id') .eq('id', id) .single() if (!thread) notFound() if (thread.space_id !== self.space_id) notFound() let authorName = 'Member' if (thread.author_id) { const { data: a } = await supabase .from('space_members') .select('display_name') .eq('id', thread.author_id) .single() if (a?.display_name) authorName = a.display_name } const comments = await loadComments(supabase, 'forum_thread', thread.id) const isAuthor = self.id === thread.author_id const canModerate = self.role === 'admin' || self.role === 'board' const canEditThread = isAuthor || canModerate return (
{authorName} · {new Date(thread.created_at).toLocaleString()}
{thread.body && (