Feed feedback and fixes #231
@ -6,6 +6,7 @@ import { Fragment } from 'react/jsx-runtime'
|
|||||||
import { BlogPreview } from './internal/BlogPreview'
|
import { BlogPreview } from './internal/BlogPreview'
|
||||||
import { ModPreview } from './internal/ModPreview'
|
import { ModPreview } from './internal/ModPreview'
|
||||||
import { NoteWrapper } from './internal/NoteWrapper'
|
import { NoteWrapper } from './internal/NoteWrapper'
|
||||||
|
import { NIP05_REGEX } from 'nostr-tools/nip05'
|
||||||
|
|
||||||
interface NoteRenderProps {
|
interface NoteRenderProps {
|
||||||
content: string
|
content: string
|
||||||
@ -16,13 +17,17 @@ const nostrMention =
|
|||||||
/(?:nostr:|@)?(?:npub|note|nprofile|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}/gi
|
/(?:nostr:|@)?(?:npub|note|nprofile|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}/gi
|
||||||
const nostrEntity =
|
const nostrEntity =
|
||||||
/(npub|note|nprofile|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}/gi
|
/(npub|note|nprofile|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58,}/gi
|
||||||
|
const nostrNip5Mention = /(?:nostr:|@)([^\s]{1,64}@[^\s]+\.[^\s]{2,})/gi
|
||||||
|
|
||||||
export const NoteRender = ({ content }: NoteRenderProps) => {
|
export const NoteRender = ({ content }: NoteRenderProps) => {
|
||||||
const _content = useMemo(() => {
|
const _content = useMemo(() => {
|
||||||
if (!content) return
|
if (!content) return
|
||||||
|
|
||||||
const parts = content.split(
|
const parts = content.split(
|
||||||
new RegExp(`(${link.source})|(${nostrMention.source})`, 'gui')
|
new RegExp(
|
||||||
|
`(${link.source})|(${nostrMention.source})|${nostrNip5Mention.source}`,
|
||||||
|
'gui'
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
const _parts = parts.map((part, index) => {
|
const _parts = parts.map((part, index) => {
|
||||||
@ -63,6 +68,9 @@ export const NoteRender = ({ content }: NoteRenderProps) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
return part
|
return part
|
||||||
}
|
}
|
||||||
|
} else if (NIP05_REGEX.test(part)) {
|
||||||
|
const [nip05] = part.match(NIP05_REGEX) || []
|
||||||
|
return <ProfileLink key={index} nip05={nip05} />
|
||||||
} else {
|
} else {
|
||||||
return part
|
return part
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { FALLBACK_PROFILE_IMAGE } from 'constants.ts'
|
import { FALLBACK_PROFILE_IMAGE } from 'constants.ts'
|
||||||
import { Event, Filter, kinds, nip19, UnsignedEvent } from 'nostr-tools'
|
import { Event, Filter, kinds, nip19, UnsignedEvent } from 'nostr-tools'
|
||||||
import { QRCodeSVG } from 'qrcode.react'
|
import { QRCodeSVG } from 'qrcode.react'
|
||||||
import { useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import {
|
import {
|
||||||
@ -27,7 +27,11 @@ import {
|
|||||||
import { LoadingSpinner } from './LoadingSpinner'
|
import { LoadingSpinner } from './LoadingSpinner'
|
||||||
import { ZapPopUp } from './Zap'
|
import { ZapPopUp } from './Zap'
|
||||||
import placeholder from '../assets/img/DEGMods Placeholder Img.png'
|
import placeholder from '../assets/img/DEGMods Placeholder Img.png'
|
||||||
import { NDKEvent, NDKSubscriptionCacheUsage } from '@nostr-dev-kit/ndk'
|
import {
|
||||||
|
NDKEvent,
|
||||||
|
NDKSubscriptionCacheUsage,
|
||||||
|
NDKUser
|
||||||
|
} from '@nostr-dev-kit/ndk'
|
||||||
import { useProfile } from 'hooks/useProfile'
|
import { useProfile } from 'hooks/useProfile'
|
||||||
import { createPortal } from 'react-dom'
|
import { createPortal } from 'react-dom'
|
||||||
|
|
||||||
@ -577,32 +581,52 @@ const FollowButton = ({ pubkey }: FollowButtonProps) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProfileLink = ({ pubkey }: Props) => {
|
type ProfileLinkProps = {
|
||||||
let hexPubkey: string | null = null
|
pubkey?: string
|
||||||
let profileRoute: string | undefined = appRoutes.home
|
nip05?: string
|
||||||
let nprofile: string | undefined
|
}
|
||||||
const npub = hexToNpub(pubkey)
|
export const ProfileLink = ({ pubkey, nip05 }: ProfileLinkProps) => {
|
||||||
|
const { ndk } = useNDKContext()
|
||||||
try {
|
console.log(`[debug]`, pubkey, nip05)
|
||||||
hexPubkey = npubToHex(pubkey)
|
const [hexPubkey, setHexPubkey] = useState<string>()
|
||||||
|
const profile = useProfile(hexPubkey, {
|
||||||
if (hexPubkey) {
|
|
||||||
nprofile = hexPubkey
|
|
||||||
? nip19.nprofileEncode({
|
|
||||||
pubkey: hexPubkey
|
|
||||||
})
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Silently ignore
|
|
||||||
log(true, LogType.Error, 'Failed to encode profile.', error)
|
|
||||||
}
|
|
||||||
|
|
||||||
profileRoute = nprofile ? getProfilePageRoute(nprofile) : appRoutes.home
|
|
||||||
const profile = useProfile(hexPubkey!, {
|
|
||||||
cacheUsage: NDKSubscriptionCacheUsage.PARALLEL
|
cacheUsage: NDKSubscriptionCacheUsage.PARALLEL
|
||||||
})
|
})
|
||||||
|
useEffect(() => {
|
||||||
|
if (pubkey) {
|
||||||
|
setHexPubkey(pubkey)
|
||||||
|
} else if (nip05) {
|
||||||
|
NDKUser.fromNip05(nip05, ndk).then((user) => {
|
||||||
|
if (user?.pubkey) {
|
||||||
|
setHexPubkey(user.pubkey)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [pubkey, nip05, ndk])
|
||||||
|
|
||||||
|
const profileRoute = useMemo(() => {
|
||||||
|
let nprofile: string | undefined
|
||||||
|
try {
|
||||||
|
if (hexPubkey) {
|
||||||
|
nprofile = hexPubkey
|
||||||
|
? nip19.nprofileEncode({
|
||||||
|
pubkey: hexPubkey
|
||||||
|
})
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Silently ignore
|
||||||
|
log(true, LogType.Error, 'Failed to encode profile.', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nprofile ? getProfilePageRoute(nprofile) : appRoutes.home
|
||||||
|
}, [hexPubkey])
|
||||||
|
|
||||||
|
const displayName = useMemo(() => {
|
||||||
|
const npub = hexPubkey ? hexToNpub(hexPubkey) : ''
|
||||||
|
const displayName = profile?.displayName || profile?.name || truncate(npub)
|
||||||
|
return displayName
|
||||||
|
}, [hexPubkey, profile?.displayName, profile?.name])
|
||||||
|
|
||||||
const displayName = profile?.displayName || profile?.name || truncate(npub)
|
|
||||||
return <Link to={profileRoute}>@{displayName}</Link>
|
return <Link to={profileRoute}>@{displayName}</Link>
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user