From ac254f69d54c7bdeaae8718b5a1cdab0335d4ce7 Mon Sep 17 00:00:00 2001 From: Bojan Mojsilovic Date: Thu, 7 Sep 2023 13:40:52 +0200 Subject: [PATCH] Hide embedded note on small notes --- src/components/ParsedNote/ParsedNote.tsx | 66 ++++++++++++++++++------ src/components/SmallNote/SmallNote.tsx | 2 +- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/components/ParsedNote/ParsedNote.tsx b/src/components/ParsedNote/ParsedNote.tsx index d60acad..cba142b 100644 --- a/src/components/ParsedNote/ParsedNote.tsx +++ b/src/components/ParsedNote/ParsedNote.tsx @@ -18,8 +18,7 @@ import { useMediaContext } from '../../contexts/MediaContext'; import { hookForDev } from '../../lib/devTools'; -export const parseNoteLinks = (text: string, note: PrimalNote, highlightOnly = false) => { - +export const parseNoteLinks = (text: string, note: PrimalNote, highlightOnly?: 'text' | 'links') => { const regex = /\bnostr:((note|nevent)1\w+)\b|#\[(\d+)\]/g; return text.replace(regex, (url) => { @@ -36,11 +35,16 @@ export const parseNoteLinks = (text: string, note: PrimalNote, highlightOnly = f const path = `/e/${noteId}`; - const ment = note.mentionedNotes && note.mentionedNotes[hex]; + let link = {url}; - const link = highlightOnly ? - {url} : - ment ? + if (highlightOnly === 'links') { + link = @{url}; + } + + if (!highlightOnly) { + const ment = note.mentionedNotes && note.mentionedNotes[hex]; + + link = ment ?
: {url}; + } // @ts-ignore return link.outerHTML || url; @@ -111,7 +116,7 @@ const ParsedNote: Component<{ const media = useMediaContext(); - const parsedContent = (text: string) => { + const parsedContent = (text: string, highlightOnly?: 'text' | 'links') => { const regex = /\#\[([0-9]*)\]/g; let parsed = text; @@ -135,15 +140,28 @@ const ParsedNote: Component<{ props.note.mentionedNotes && props.note.mentionedNotes[tag[1]] ) { - const embeded = ( -
- -
- ); + const hex = tag[1]; + const noteId = `nostr:${nip19.noteEncode(hex)}`; + const path = `/e/${nip19.noteEncode(hex)}`; + let embeded = {noteId}; + + if (highlightOnly === 'links') { + embeded = @{noteId}; + } + + if (!highlightOnly) { + const ment = props.note.mentionedNotes[hex]; + + embeded = ment ? +
+ +
: + {noteId}; + } // @ts-ignore parsed = parsed.replace(`#[${r}]`, embeded.outerHTML); @@ -152,7 +170,19 @@ const ParsedNote: Component<{ if (tag[0] === 'p' && props.note.mentionedUsers && props.note.mentionedUsers[tag[1]]) { const user = props.note.mentionedUsers[tag[1]]; - const link = MentionedUserLink({ user }); + const path = `/p/${user.npub}`; + + const label = userName(user); + + let link = @{label}; + + if (highlightOnly === 'links') { + link = @{label}; + } + + if (!highlightOnly) { + link = user ? @{label} : MentionedUserLink({ user }); + } // @ts-ignore parsed = parsed.replace(`#[${r}]`, link.outerHTML); @@ -218,11 +248,13 @@ const ParsedNote: Component<{ highlightHashtags( parseNote1(props.note.post.content, media?.actions.getMediaUrl) ), + props.noLinks, ), props.note, props.noLinks, ), props.note, + props.noLinks, ); }; @@ -234,11 +266,13 @@ const ParsedNote: Component<{ props.note.post.content, props.noLinks, ), + props.noLinks, ), props.note, props.noLinks, ), props.note, + props.noLinks, ); }; diff --git a/src/components/SmallNote/SmallNote.tsx b/src/components/SmallNote/SmallNote.tsx index 005bf44..af6a38d 100644 --- a/src/components/SmallNote/SmallNote.tsx +++ b/src/components/SmallNote/SmallNote.tsx @@ -73,7 +73,7 @@ const SmallNote: Component<{ note: PrimalNote, children?: JSXElement, id?: strin }; return ( -
+