import React, { useState, useEffect } from 'react'; import { Card } from 'primereact/card'; import { Avatar } from 'primereact/avatar'; import { Tag } from 'primereact/tag'; import { Button } from 'primereact/button'; import { ProgressSpinner } from 'primereact/progressspinner'; import { useNDKContext } from '@/context/NDKContext'; import { findKind0Fields } from '@/utils/nostr'; import NostrIcon from '../../../public/images/nostr.png'; import Image from 'next/image'; import { useImageProxy } from '@/hooks/useImageProxy'; import { nip19 } from 'nostr-tools'; import { useCommunityNotes } from '@/hooks/nostr/useCommunityNotes'; const NostrFeed = () => { const { communityNotes, isLoading, error } = useCommunityNotes(); const { ndk } = useNDKContext(); const { returnImageProxy } = useImageProxy(); const [authorData, setAuthorData] = useState({}); useEffect(() => { communityNotes.forEach(note => { if (!authorData[note.pubkey]) { fetchAuthor(note.pubkey); } }); }, [communityNotes, authorData]); const fetchAuthor = async (pubkey) => { try { const filter = { kinds: [0], authors: [pubkey] }; const author = await ndk.fetchEvent(filter); if (author) { try { const fields = await findKind0Fields(JSON.parse(author.content)); setAuthorData(prevData => ({ ...prevData, [pubkey]: fields })); } catch (error) { console.error('Error fetching author:', error); } } } catch (error) { console.error('Error fetching author:', error); } }; const renderHeader = (message) => { const author = authorData[message.pubkey]; if (!author || Object.keys(author).length === 0 || !author.username || !author.avatar) { return null; } return (
{author?.username || author?.pubkey.substring(0, 12) + '...'}
{message.content}