feat: display i value

This commit is contained in:
codytseng
2025-05-25 15:44:19 +08:00
parent 01462da65f
commit a319204910
15 changed files with 65 additions and 13 deletions

View File

@@ -0,0 +1,36 @@
import { ExtendedKind } from '@/constants'
import { tagNameEquals } from '@/lib/tag'
import { cn } from '@/lib/utils'
import { Event } from 'nostr-tools'
import { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
export default function IValue({ event, className }: { event: Event; className?: string }) {
const { t } = useTranslation()
const iValue = useMemo(() => {
if (event.kind !== ExtendedKind.COMMENT) return undefined
const iTag = event.tags.find(tagNameEquals('i'))
return iTag ? iTag[1] : undefined
}, [event])
if (!iValue) return null
return (
<div className={cn('truncate text-muted-foreground', className)}>
{t('Comment on') + ' '}
{iValue.startsWith('http') ? (
<a
className="hover:text-foreground underline truncate"
href={iValue}
target="_blank"
rel="noopener noreferrer"
onClick={(e) => e.stopPropagation()}
>
{iValue}
</a>
) : (
<span>{iValue}</span>
)}
</div>
)
}

View File

@@ -17,6 +17,7 @@ import ParentNotePreview from '../ParentNotePreview'
import UserAvatar from '../UserAvatar'
import Username from '../Username'
import Highlight from './Highlight'
import IValue from './IValue'
import { UnknownNote } from './UnknownNote'
export default function Note({
@@ -76,6 +77,7 @@ export default function Note({
}}
/>
)}
<IValue event={event} className="mt-2" />
{event.kind === kinds.Highlights ? (
<Highlight className="mt-2" event={event} />
) : isSupportedKind(event.kind) ? (