import React, { useState } from 'react'; import { useProfile } from "nostr-react"; import { nip19, } from "nostr-tools"; import { Card, SmallCardContent, } from "@/components/ui/card" import Link from 'next/link'; import Image from 'next/image'; import { extractDimensions, getProxiedImageUrl } from '@/utils/utils'; interface QuickViewKind20NoteCardProps { pubkey: string; text: string; image: string; eventId: string; tags: string[][]; event: any; linkToNote: boolean; } const QuickViewKind20NoteCard: React.FC = ({ pubkey, text, image, eventId, tags, event, linkToNote }) => { const {data, isLoading} = useProfile({ pubkey, }); const [imageError, setImageError] = useState(false); const [tryWithoutProxy, setTryWithoutProxy] = useState(false); if (!image || !image.startsWith("http")) return null; if (imageError && tryWithoutProxy) return null; const useImgProxy = process.env.NEXT_PUBLIC_ENABLE_IMGPROXY === "true" && !tryWithoutProxy; image = useImgProxy ? getProxiedImageUrl(image, 500, 0) : image; text = text.replaceAll('\n', ' '); const encodedNoteId = nip19.noteEncode(event.id) const { width, height } = extractDimensions(event); const card = (
{text} { if (tryWithoutProxy) { setImageError(true); } else { setTryWithoutProxy(true); } }} style={{ objectPosition: 'center' }} />
); return ( <> {linkToNote ? ( {card} ) : ( card )} ); } export default QuickViewKind20NoteCard;