From a3192049107a81363b2de4ab2dbc991046d27a49 Mon Sep 17 00:00:00 2001 From: codytseng Date: Sun, 25 May 2025 15:44:19 +0800 Subject: [PATCH] feat: display i value --- src/components/Note/IValue.tsx | 36 ++++++++++++++++++++++++++++++++++ src/components/Note/index.tsx | 2 ++ src/i18n/locales/ar.ts | 3 ++- src/i18n/locales/de.ts | 3 ++- src/i18n/locales/en.ts | 3 ++- src/i18n/locales/es.ts | 3 ++- src/i18n/locales/fr.ts | 3 ++- src/i18n/locales/it.ts | 3 ++- src/i18n/locales/ja.ts | 3 ++- src/i18n/locales/pl.ts | 3 ++- src/i18n/locales/pt-BR.ts | 3 ++- src/i18n/locales/pt-PT.ts | 3 ++- src/i18n/locales/ru.ts | 3 ++- src/i18n/locales/zh.ts | 3 ++- src/lib/event.ts | 4 +++- 15 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 src/components/Note/IValue.tsx diff --git a/src/components/Note/IValue.tsx b/src/components/Note/IValue.tsx new file mode 100644 index 00000000..6df2afab --- /dev/null +++ b/src/components/Note/IValue.tsx @@ -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 ( +
+ {t('Comment on') + ' '} + {iValue.startsWith('http') ? ( + e.stopPropagation()} + > + {iValue} + + ) : ( + {iValue} + )} +
+ ) +} diff --git a/src/components/Note/index.tsx b/src/components/Note/index.tsx index d1249841..d2831a38 100644 --- a/src/components/Note/index.tsx +++ b/src/components/Note/index.tsx @@ -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({ }} /> )} + {event.kind === kinds.Highlights ? ( ) : isSupportedKind(event.kind) ? ( diff --git a/src/i18n/locales/ar.ts b/src/i18n/locales/ar.ts index 76e67c9a..aea8e5ce 100644 --- a/src/i18n/locales/ar.ts +++ b/src/i18n/locales/ar.ts @@ -231,6 +231,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'أنت على وشك نشر حدث موقع من قبل [{{eventAuthorName}}]. أنت حالياً مسجل الدخول كـ [{{currentUsername}}]. هل أنت متأكد؟', 'Platinum Sponsors': 'الرعاة البلاتينيون', - From: 'من' + From: 'من', + 'Comment on': 'تعليق على' } } diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts index d29435e2..3eab03ec 100644 --- a/src/i18n/locales/de.ts +++ b/src/i18n/locales/de.ts @@ -237,6 +237,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'Du bist dabei, ein Ereignis zu veröffentlichen, das von [{{eventAuthorName}}] signiert wurde. Du bist derzeit als [{{currentUsername}}] angemeldet. Bist du sicher?', 'Platinum Sponsors': 'Platin-Sponsoren', - From: 'Von' + From: 'Von', + 'Comment on': 'Kommentar zu' } } diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts index 407b46d5..f337a81e 100644 --- a/src/i18n/locales/en.ts +++ b/src/i18n/locales/en.ts @@ -231,6 +231,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?', 'Platinum Sponsors': 'Platinum Sponsors', - From: 'From' + From: 'From', + 'Comment on': 'Comment on' } } diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts index f896190f..d5bfe963 100644 --- a/src/i18n/locales/es.ts +++ b/src/i18n/locales/es.ts @@ -236,6 +236,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'Estás a punto de publicar un evento firmado por [{{eventAuthorName}}]. Actualmente has iniciado sesión como [{{currentUsername}}]. ¿Estás seguro?', 'Platinum Sponsors': 'Patrocinadores Platino', - From: 'De' + From: 'De', + 'Comment on': 'Comentar en' } } diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.ts index 7b06433c..eb642dab 100644 --- a/src/i18n/locales/fr.ts +++ b/src/i18n/locales/fr.ts @@ -236,6 +236,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'Vous êtes sur le point de publier un événement signé par [{{eventAuthorName}}]. Vous êtes actuellement connecté en tant que [{{currentUsername}}]. Êtes-vous sûr ?', 'Platinum Sponsors': 'Sponsors Platine', - From: 'De' + From: 'De', + 'Comment on': 'Commenter sur' } } diff --git a/src/i18n/locales/it.ts b/src/i18n/locales/it.ts index 25be8d05..7b9cef34 100644 --- a/src/i18n/locales/it.ts +++ b/src/i18n/locales/it.ts @@ -235,6 +235,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'Stai per pubblicare un evento firmato da [{{eventAuthorName}}]. Attualmente sei connesso come [{{currentUsername}}]. Sei sicuro?', 'Platinum Sponsors': 'Sponsor Platino', - From: 'Da' + From: 'Da', + 'Comment on': 'Commenta su' } } diff --git a/src/i18n/locales/ja.ts b/src/i18n/locales/ja.ts index 42d07d0b..86722931 100644 --- a/src/i18n/locales/ja.ts +++ b/src/i18n/locales/ja.ts @@ -232,6 +232,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'あなたは[{{eventAuthorName}}]によって署名されたイベントを公開しようとしています。現在[{{currentUsername}}]としてログインしています。よろしいですか?', 'Platinum Sponsors': 'プラチナスポンサー', - From: 'から' + From: 'から', + 'Comment on': 'にコメント' } } diff --git a/src/i18n/locales/pl.ts b/src/i18n/locales/pl.ts index 263a6b1f..47f16a7f 100644 --- a/src/i18n/locales/pl.ts +++ b/src/i18n/locales/pl.ts @@ -234,6 +234,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'Zaraz opublikujesz zdarzenie podpisane przez [{{eventAuthorName}}]. Obecnie jesteś zalogowany jako [{{currentUsername}}]. Czy jesteś pewien?', 'Platinum Sponsors': 'Sponsorzy Platynowi', - From: 'Od' + From: 'Od', + 'Comment on': 'Komentarz do' } } diff --git a/src/i18n/locales/pt-BR.ts b/src/i18n/locales/pt-BR.ts index 530d4e4f..e14e3b6f 100644 --- a/src/i18n/locales/pt-BR.ts +++ b/src/i18n/locales/pt-BR.ts @@ -234,6 +234,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'Você está prestes a publicar um evento assinado por [{{eventAuthorName}}]. Você está atualmente logado como [{{currentUsername}}]. Tem certeza?', 'Platinum Sponsors': 'Patrocinadores Platinum', - From: 'De' + From: 'De', + 'Comment on': 'Comentar em' } } diff --git a/src/i18n/locales/pt-PT.ts b/src/i18n/locales/pt-PT.ts index 54f57641..a46b6970 100644 --- a/src/i18n/locales/pt-PT.ts +++ b/src/i18n/locales/pt-PT.ts @@ -235,6 +235,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'Você está prestes a publicar um evento assinado por [{{eventAuthorName}}]. Você está atualmente logado como [{{currentUsername}}]. Tem certeza?', 'Platinum Sponsors': 'Patrocinadores Platinum', - From: 'De' + From: 'De', + 'Comment on': 'Comentar em' } } diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.ts index 2ba95268..8f2e8774 100644 --- a/src/i18n/locales/ru.ts +++ b/src/i18n/locales/ru.ts @@ -235,6 +235,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': 'Вы собираетесь опубликовать событие, подписанное [{{eventAuthorName}}]. Вы в данный момент вошли как [{{currentUsername}}]. Вы уверены?', 'Platinum Sponsors': 'Платиновые спонсоры', - From: 'От' + From: 'От', + 'Comment on': 'Прокомментировать' } } diff --git a/src/i18n/locales/zh.ts b/src/i18n/locales/zh.ts index eb33e57d..28650b03 100644 --- a/src/i18n/locales/zh.ts +++ b/src/i18n/locales/zh.ts @@ -232,6 +232,7 @@ export default { 'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?': '您即将发布一条由 [{{eventAuthorName}}] 签名的事件。您当前以 [{{currentUsername}}] 登录。确定吗?', 'Platinum Sponsors': '白金赞助商', - From: '来自' + From: '来自', + 'Comment on': '评论于' } } diff --git a/src/lib/event.ts b/src/lib/event.ts index e3a46863..02c21508 100644 --- a/src/lib/event.ts +++ b/src/lib/event.ts @@ -26,7 +26,9 @@ export function isNsfwEvent(event: Event) { } export function isReplyNoteEvent(event: Event) { - if (event.kind === ExtendedKind.COMMENT) return true + if (event.kind === ExtendedKind.COMMENT) { + return !!getParentEventTag(event) + } if (event.kind !== kinds.ShortTextNote) return false const cache = EVENT_IS_REPLY_NOTE_CACHE.get(event.id)