import { NDKKind } from '@nostr-dev-kit/ndk' import { formatDate } from 'date-fns' import { useDidMount, useNDKContext } from 'hooks' import { useState } from 'react' import { useParams, useLocation, Link } from 'react-router-dom' import { getModPageRoute, getBlogPageRoute, getProfilePageRoute } from 'routes' import { CommentEvent, UserProfile } from 'types' import { hexToNpub } from 'utils' import { Reactions } from './Reactions' import { Zap } from './Zap' import { nip19 } from 'nostr-tools' import { CommentContent } from './CommentContent' interface CommentProps { comment: CommentEvent } export const Comment = ({ comment }: CommentProps) => { const { naddr } = useParams() const location = useLocation() const { ndk } = useNDKContext() const isMod = location.pathname.includes('/mod/') const isBlog = location.pathname.includes('/blog/') const baseUrl = naddr ? isMod ? getModPageRoute(naddr) : isBlog ? getBlogPageRoute(naddr) : undefined : undefined const [commentEvents, setCommentEvents] = useState([]) const [profile, setProfile] = useState() useDidMount(() => { comment.event.author.fetchProfile().then((res) => setProfile(res)) ndk .fetchEvents({ kinds: [NDKKind.Text, NDKKind.GenericReply], '#e': [comment.event.id] }) .then((ndkEventsSet) => { setCommentEvents( Array.from(ndkEventsSet).map((ndkEvent) => ({ event: ndkEvent })) ) }) }) const profileRoute = getProfilePageRoute( nip19.nprofileEncode({ pubkey: comment.event.pubkey }) ) return (
{profile?.displayName || profile?.name || ''}{' '} {hexToNpub(comment.event.pubkey)}
{comment.event.created_at && ( )}
{comment.status && (

Status: {comment.status}

)}

0

{typeof profile?.lud16 !== 'undefined' && profile.lud16 !== '' && ( )} {comment.event.kind === NDKKind.GenericReply && ( <>

{commentEvents.length}

Replies

Reply

)}
) }