import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; import { Card, CardContent } from '@/components/ui/card'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { usePostComment } from '@/hooks/usePostComment'; import { LoginArea } from '@/components/auth/LoginArea'; import { NostrEvent } from '@nostrify/nostrify'; import { MessageSquare, Send } from 'lucide-react'; interface CommentFormProps { root: NostrEvent | URL; reply?: NostrEvent | URL; 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 (