diff --git a/src/components/reply.tsx b/src/components/reply.tsx index 6e9f775c..48d005d7 100644 --- a/src/components/reply.tsx +++ b/src/components/reply.tsx @@ -7,7 +7,18 @@ import { Link, useSearch } from "@tanstack/react-router"; import { useStore } from "@tanstack/react-store"; import { Menu, MenuItem } from "@tauri-apps/api/menu"; import { writeText } from "@tauri-apps/plugin-clipboard-manager"; -import { memo, useCallback, useEffect, useState } from "react"; +import { nip19 } from "nostr-tools"; +import { + type ReactNode, + memo, + useCallback, + useEffect, + useMemo, + useState, +} from "react"; +import reactStringReplace from "react-string-replace"; +import { Hashtag } from "./note/mentions/hashtag"; +import { MentionUser } from "./note/mentions/user"; import { User } from "./user"; export const ReplyNote = memo(function ReplyNote({ @@ -19,6 +30,7 @@ export const ReplyNote = memo(function ReplyNote({ }) { const trustedOnly = useStore(appSettings, (state) => state.trusted_only); const search = useSearch({ strict: false }); + const [isTrusted, setIsTrusted] = useState(null); const showContextMenu = useCallback(async (e: React.MouseEvent) => { @@ -75,12 +87,13 @@ export const ReplyNote = memo(function ReplyNote({
-
- {event.content} -
+
@@ -153,14 +166,15 @@ function ChildReply({ event }: { event: LumeEvent }) {
- + -
- {event.content} -
+
@@ -200,3 +214,64 @@ function ChildReply({ event }: { event: LumeEvent }) { ); } + +function Content({ text, className }: { text: string; className?: string }) { + const content = useMemo(() => { + let replacedText: ReactNode[] | string = text.trim(); + + const nostr = replacedText + .split(/\s+/) + .filter((w) => w.startsWith("nostr:")); + + replacedText = reactStringReplace(text, /(https?:\/\/\S+)/g, (match, i) => ( + + {match} + + )); + + replacedText = reactStringReplace(replacedText, /#(\w+)/g, (match, i) => ( + + )); + + for (const word of nostr) { + const bech32 = word.replace("nostr:", ""); + const data = nip19.decode(bech32); + + switch (data.type) { + case "npub": + replacedText = reactStringReplace(replacedText, word, (match, i) => ( + + )); + break; + case "nprofile": + replacedText = reactStringReplace(replacedText, word, (match, i) => ( + + )); + break; + default: + replacedText = reactStringReplace(replacedText, word, (match, i) => ( + + {match} + + )); + break; + } + } + + return replacedText; + }, [text]); + + return
{content}
; +}