import { type ReactNode } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'; import { Skeleton } from '@/components/ui/skeleton'; import { EmojifiedText } from '@/components/CustomEmoji'; import { ProfileHoverCard } from '@/components/ProfileHoverCard'; import { useAuthor } from '@/hooks/useAuthor'; import { genUserName } from '@/lib/genUserName'; import { useProfileUrl } from '@/hooks/useProfileUrl'; import { timeAgo } from '@/lib/timeAgo'; import { cn } from '@/lib/utils'; interface EmbeddedCardShellProps { /** Author pubkey — used for the author row. */ pubkey: string; /** Timestamp of the event (unix seconds). */ createdAt: number; /** The NIP-19 identifier to navigate to on click. */ navigateTo: string; className?: string; /** When true, ProfileHoverCards inside the card are disabled. */ disableHoverCards?: boolean; children: ReactNode; } /** * Shared clickable card shell with an author row used by all embedded * note / naddr preview cards. Handles the outer border, hover style, * click / keyboard navigation, avatar, display name, and timestamp. * * Pass card-specific content (text preview, badge row, etc.) * as `children`. */ export function EmbeddedCardShell({ pubkey, createdAt, navigateTo, className, disableHoverCards, children, }: EmbeddedCardShellProps) { const navigate = useNavigate(); const author = useAuthor(pubkey); const metadata = author.data?.metadata; const displayName = metadata?.name || genUserName(pubkey); const profileUrl = useProfileUrl(pubkey, metadata); return (
{ e.stopPropagation(); navigate(`/${navigateTo}`); }} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); e.stopPropagation(); navigate(`/${navigateTo}`); } }} >
{/* Author row */}
{author.isLoading ? ( <> ) : ( <> e.stopPropagation()} > {displayName[0]?.toUpperCase()} e.stopPropagation()} > {author.data?.event ? ( {displayName} ) : displayName} )} · {timeAgo(createdAt)}
{children}
); } /** Conditionally wraps children in a ProfileHoverCard. */ function MaybeProfileHoverCard({ pubkey, disabled, children }: { pubkey: string; disabled?: boolean; children: ReactNode }) { if (disabled) { return <>{children}; } return ( {children} ); }