import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { usePostComment } from '@/hooks/usePostComment'; import { LoginArea } from '@/components/auth/LoginArea'; import { NostrEvent } from '@nostrify/nostrify'; import { MessageSquare } from 'lucide-react'; import { cn } from '@/lib/utils'; interface CommentFormProps { root: NostrEvent | URL | `#${string}`; reply?: NostrEvent | URL | `#${string}`; onSuccess?: () => void; placeholder?: string; compact?: boolean; } export function CommentForm({ root, reply, onSuccess, placeholder = "Write a comment...", compact = false, }: CommentFormProps) { const [content, setContent] = useState(''); const { user } = useCurrentUser(); const { mutate: postComment, isPending } = usePostComment(); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!content.trim() || !user) return; postComment( { content: content.trim(), root, reply }, { onSuccess: () => { setContent(''); onSuccess?.(); }, } ); }; if (!user) { return (
Sign in to {reply ? 'reply' : 'comment'}
); } return (