import React from 'react'; import { useProfile } from "nostr-react"; import { nip19 } from "nostr-tools"; import { Card, CardHeader, CardTitle, SmallCardContent, } from "@/components/ui/card" import Link from 'next/link'; import { Avatar } from './ui/avatar'; import { AvatarImage } from '@radix-ui/react-avatar'; interface TrendingImageNewProps { event: { id: string; pubkey: string; content: string; created_at: string; tags: Array; } } const TrendingImageNew: React.FC = ({ event }) => { const { data: userData } = useProfile({ pubkey: event.pubkey, }); const npubShortened = (() => { let encoded = nip19.npubEncode(event.pubkey); let parts = encoded.split('npub'); return 'npub' + parts[1].slice(0, 4) + ':' + parts[1].slice(-3); })(); const title = userData?.username || userData?.display_name || userData?.name || userData?.npub || npubShortened; const text = event.content.replaceAll('\n', ' '); // Get image URL from imeta tags const imageUrl = event.tags.find(tag => tag[0] === 'imeta' && tag[1]?.startsWith('url ')) ?.slice(1)[0]?.replace('url ', ''); const hrefProfile = `/profile/${nip19.npubEncode(event.pubkey)}`; const hrefNote = `/note/${nip19.noteEncode(event.id)}`; const profileImageSrc = userData?.picture || "https://robohash.org/" + event.pubkey; return (
{title}
{imageUrl && (
{text}
)}
); } export default TrendingImageNew;