'use client' import { useRouter } from 'next/navigation' import { toast } from 'sonner' import { Pin, Lock, Trash2 } from 'lucide-react' import { updateForumThread, deleteForumThread } from '@/lib/actions' import { useConfirm } from '@/components/ui/confirm' interface Props { threadId: string pinned: boolean locked: boolean canModerate: boolean isAuthor: boolean } export function ThreadActions({ threadId, pinned, locked, canModerate, isAuthor }: Props) { const router = useRouter() const confirm = useConfirm() async function togglePinned() { const result = await updateForumThread(threadId, { pinned: !pinned }) if (result.error) { toast.error(result.error); return } router.refresh() } async function toggleLocked() { const result = await updateForumThread(threadId, { locked: !locked }) if (result.error) { toast.error(result.error); return } router.refresh() } async function handleDelete() { if (!(await confirm({ title: 'Delete thread', description: 'All comments are deleted too. This cannot be undone.', confirmText: 'Delete', destructive: true }))) return const result = await deleteForumThread(threadId) if (result.error) { toast.error(result.error); return } toast.success('Thread deleted') router.push('/forum') } return (
{canModerate && ( <> )} {(isAuthor || canModerate) && ( )}
) }