mirror of
https://github.com/dergigi/boris.git
synced 2025-12-18 15:14:20 +01:00
- Update nostrUriResolver to return internal /p/:npub links for npub/nprofile - Replace external profile links with React Router Link components - Update ResolvedMention, LargeView, and CardView components - Convert nprofile to npub before routing - Keep note/nevent links as external (no internal viewer yet)
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import React from 'react'
|
|
import { Link } from 'react-router-dom'
|
|
import { useEventModel } from 'applesauce-react/hooks'
|
|
import { Models, Helpers } from 'applesauce-core'
|
|
import { decode, npubEncode } from 'nostr-tools/nip19'
|
|
|
|
const { getPubkeyFromDecodeResult } = Helpers
|
|
|
|
interface ResolvedMentionProps {
|
|
encoded?: string
|
|
}
|
|
|
|
const ResolvedMention: React.FC<ResolvedMentionProps> = ({ encoded }) => {
|
|
if (!encoded) return null
|
|
let pubkey: string | undefined
|
|
try {
|
|
pubkey = getPubkeyFromDecodeResult(decode(encoded))
|
|
} catch {
|
|
// ignore; will fallback to showing the encoded value
|
|
}
|
|
|
|
const profile = pubkey ? useEventModel(Models.ProfileModel, [pubkey]) : undefined
|
|
const display = profile?.name || profile?.display_name || profile?.nip05 || (pubkey ? `${pubkey.slice(0, 8)}...` : encoded)
|
|
const npub = pubkey ? npubEncode(pubkey) : undefined
|
|
|
|
if (npub) {
|
|
return (
|
|
<Link
|
|
to={`/p/${npub}`}
|
|
className="nostr-mention"
|
|
>
|
|
@{display}
|
|
</Link>
|
|
)
|
|
}
|
|
|
|
return <span className="nostr-mention">{encoded}</span>
|
|
}
|
|
|
|
export default ResolvedMention
|
|
|
|
|