mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
- Add getProfileDisplayName() utility function for consistent profile name resolution - Update all components to use standardized npub fallback format instead of hex - Fix useProfileLabels hook to include fallback npub labels when profiles lack names - Refactor NostrMentionLink to eliminate duplication between npub/nprofile cases - Remove debug console.log statements from RichContent component - Update AuthorCard, SidebarHeader, HighlightItem, Support, BlogPostCard, ResolvedMention, and useEventLoader to use new utilities
44 lines
1.1 KiB
TypeScript
44 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'
|
|
import { getProfileDisplayName } from '../utils/nostrUriResolver'
|
|
|
|
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 = pubkey ? getProfileDisplayName(profile, pubkey) : 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
|
|
|
|
|