import { useState } from 'react'; import { Link } from 'react-router-dom'; import { NostrEvent } from '@nostrify/nostrify'; import { nip19 } from 'nostr-tools'; import { useAuthor } from '@/hooks/useAuthor'; import { useComments } from '@/hooks/useComments'; import { CommentForm } from './CommentForm'; import { NoteContent } from '@/components/NoteContent'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'; import { DropdownMenu, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; import { MessageSquare, ChevronDown, ChevronRight, MoreHorizontal } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; import { genUserName } from '@/lib/genUserName'; interface CommentProps { root: NostrEvent | URL; comment: NostrEvent; depth?: number; maxDepth?: number; limit?: number; } export function Comment({ root, comment, depth = 0, maxDepth = 3, limit }: CommentProps) { const [showReplyForm, setShowReplyForm] = useState(false); const [showReplies, setShowReplies] = useState(depth < 2); // Auto-expand first 2 levels const author = useAuthor(comment.pubkey); const { data: commentsData } = useComments(root, limit); const metadata = author.data?.metadata; const displayName = metadata?.name ?? genUserName(comment.pubkey) const timeAgo = formatDistanceToNow(new Date(comment.created_at * 1000), { addSuffix: true }); // Get direct replies to this comment const replies = commentsData?.getDirectReplies(comment.id) || []; const hasReplies = replies.length > 0; return (
{timeAgo}