import React from 'react'; import Image from 'next/image'; import { useImageProxy } from '@/hooks/useImageProxy'; import { formatUnixTimestamp } from '@/utils/time'; import { Tag } from 'primereact/tag'; import { Message } from 'primereact/message'; import GenericButton from '@/components/buttons/GenericButton'; import useWindowWidth from '@/hooks/useWindowWidth'; import { BookOpen } from 'lucide-react'; import { highlightText, getTextWithMatchContext } from '@/utils/text'; import { generateNaddr } from '@/utils/nostr'; const ContentDropdownItem = ({ content, onSelect }) => { const { returnImageProxy } = useImageProxy(); const windowWidth = useWindowWidth(); const isMobile = windowWidth <= 600; // Get match information if available const matches = content?._matches || {}; // Handle content selection with naddress const handleSelect = () => { // Create a copy of the content object with naddress information const contentWithNaddr = { ...content }; // If content has pubkey, kind, and identifier (d tag), generate naddr if (content.pubkey && content.kind && (content.d || content.identifier)) { // Use the appropriate identifier (d tag value) const identifier = content.d || content.identifier; // Generate naddress contentWithNaddr.naddress = generateNaddr( content.pubkey, content.kind, identifier ); // Log success or failure if (contentWithNaddr.naddress) { console.log(`Generated naddress for ${content.type || 'content'}: ${contentWithNaddr.naddress}`); } else { console.warn('Failed to generate naddress:', { pubkey: content.pubkey, kind: content.kind, identifier }); } } onSelect(contentWithNaddr); }; return (
{matches.description ? highlightText( getTextWithMatchContext(content.summary, matches.description.term, 60), matches.description.term, 'bg-yellow-500/30 text-white font-medium px-0.5 rounded' ) : content.summary}
)}