import React, { useMemo } from 'react'; import { useNostr, useNostrEvents, useProfile } from "nostr-react"; import { nip19, } from "nostr-tools"; import { Card, CardHeader, CardTitle, SmallCardContent, } from "@/components/ui/card" import Image from 'next/image'; import Link from 'next/link'; import { Avatar } from './ui/avatar'; import { AvatarImage } from '@radix-ui/react-avatar'; interface TrendingImageProps { eventId: string; pubkey: string; } const TrendingImage: React.FC = ({ eventId, pubkey }) => { const { data: userData } = useProfile({ pubkey, }); const { events } = useNostrEvents({ filter: { kinds: [1], ids: [eventId] }, }); const npubShortened = useMemo(() => { let encoded = nip19.npubEncode(pubkey); let parts = encoded.split('npub'); return 'npub' + parts[1].slice(0, 4) + ':' + parts[1].slice(-3); }, [pubkey]); let text = events && events.length > 0 ? events[0].content : ''; const createdAt = events && events.length > 0 ? new Date(events[0].created_at * 1000) : new Date(); const title = userData?.username || userData?.display_name || userData?.name || userData?.npub || npubShortened; text = text.replaceAll('\n', ' '); const imageSrc = text.match(/https?:\/\/[^ ]*\.(png|jpg|gif|jpeg)/g); const textWithoutImage = text.replace(/https?:\/\/.*\.(?:png|jpg|gif|jpeg)/g, ''); const hrefProfile = `/profile/${nip19.npubEncode(pubkey)}`; const hrefNote = `/note/${nip19.noteEncode(eventId)}`; const profileImageSrc = userData?.picture || "https://robohash.org/" + pubkey; return ( <>
{title}
{imageSrc && imageSrc.length > 0 && (
{text}
// {text} //
// {text} //
)}
); } export default TrendingImage;