mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-01 17:31:13 +00:00
Hide embedded note on small notes
This commit is contained in:
parent
96d09dcb99
commit
ac254f69d5
@ -18,8 +18,7 @@ import { useMediaContext } from '../../contexts/MediaContext';
|
|||||||
import { hookForDev } from '../../lib/devTools';
|
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;
|
const regex = /\bnostr:((note|nevent)1\w+)\b|#\[(\d+)\]/g;
|
||||||
|
|
||||||
return text.replace(regex, (url) => {
|
return text.replace(regex, (url) => {
|
||||||
@ -36,11 +35,16 @@ export const parseNoteLinks = (text: string, note: PrimalNote, highlightOnly = f
|
|||||||
|
|
||||||
const path = `/e/${noteId}`;
|
const path = `/e/${noteId}`;
|
||||||
|
|
||||||
|
let link = <span>{url}</span>;
|
||||||
|
|
||||||
|
if (highlightOnly === 'links') {
|
||||||
|
link = <span class='linkish'>@{url}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!highlightOnly) {
|
||||||
const ment = note.mentionedNotes && note.mentionedNotes[hex];
|
const ment = note.mentionedNotes && note.mentionedNotes[hex];
|
||||||
|
|
||||||
const link = highlightOnly ?
|
link = ment ?
|
||||||
<span class='linkish' >{url}</span> :
|
|
||||||
ment ?
|
|
||||||
<div>
|
<div>
|
||||||
<EmbeddedNote
|
<EmbeddedNote
|
||||||
note={ment}
|
note={ment}
|
||||||
@ -48,6 +52,7 @@ export const parseNoteLinks = (text: string, note: PrimalNote, highlightOnly = f
|
|||||||
/>
|
/>
|
||||||
</div> :
|
</div> :
|
||||||
<A href={path}>{url}</A>;
|
<A href={path}>{url}</A>;
|
||||||
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return link.outerHTML || url;
|
return link.outerHTML || url;
|
||||||
@ -111,7 +116,7 @@ const ParsedNote: Component<{
|
|||||||
|
|
||||||
const media = useMediaContext();
|
const media = useMediaContext();
|
||||||
|
|
||||||
const parsedContent = (text: string) => {
|
const parsedContent = (text: string, highlightOnly?: 'text' | 'links') => {
|
||||||
const regex = /\#\[([0-9]*)\]/g;
|
const regex = /\#\[([0-9]*)\]/g;
|
||||||
let parsed = text;
|
let parsed = text;
|
||||||
|
|
||||||
@ -135,15 +140,28 @@ const ParsedNote: Component<{
|
|||||||
props.note.mentionedNotes &&
|
props.note.mentionedNotes &&
|
||||||
props.note.mentionedNotes[tag[1]]
|
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 = <span>{noteId}</span>;
|
||||||
|
|
||||||
|
if (highlightOnly === 'links') {
|
||||||
|
embeded = <span class='linkish'>@{noteId}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!highlightOnly) {
|
||||||
|
const ment = props.note.mentionedNotes[hex];
|
||||||
|
|
||||||
|
embeded = ment ?
|
||||||
<div>
|
<div>
|
||||||
<EmbeddedNote
|
<EmbeddedNote
|
||||||
note={props.note.mentionedNotes[tag[1]]}
|
note={ment}
|
||||||
mentionedUsers={props.note.mentionedUsers}
|
mentionedUsers={props.note.mentionedUsers}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div> :
|
||||||
);
|
<A href={path}>{noteId}</A>;
|
||||||
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
parsed = parsed.replace(`#[${r}]`, embeded.outerHTML);
|
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]]) {
|
if (tag[0] === 'p' && props.note.mentionedUsers && props.note.mentionedUsers[tag[1]]) {
|
||||||
const user = 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 = <span>@{label}</span>;
|
||||||
|
|
||||||
|
if (highlightOnly === 'links') {
|
||||||
|
link = <span class='linkish'>@{label}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!highlightOnly) {
|
||||||
|
link = user ? <A href={path}>@{label}</A> : MentionedUserLink({ user });
|
||||||
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
parsed = parsed.replace(`#[${r}]`, link.outerHTML);
|
parsed = parsed.replace(`#[${r}]`, link.outerHTML);
|
||||||
@ -218,11 +248,13 @@ const ParsedNote: Component<{
|
|||||||
highlightHashtags(
|
highlightHashtags(
|
||||||
parseNote1(props.note.post.content, media?.actions.getMediaUrl)
|
parseNote1(props.note.post.content, media?.actions.getMediaUrl)
|
||||||
),
|
),
|
||||||
|
props.noLinks,
|
||||||
),
|
),
|
||||||
props.note,
|
props.note,
|
||||||
props.noLinks,
|
props.noLinks,
|
||||||
),
|
),
|
||||||
props.note,
|
props.note,
|
||||||
|
props.noLinks,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -234,11 +266,13 @@ const ParsedNote: Component<{
|
|||||||
props.note.post.content,
|
props.note.post.content,
|
||||||
props.noLinks,
|
props.noLinks,
|
||||||
),
|
),
|
||||||
|
props.noLinks,
|
||||||
),
|
),
|
||||||
props.note,
|
props.note,
|
||||||
props.noLinks,
|
props.noLinks,
|
||||||
),
|
),
|
||||||
props.note,
|
props.note,
|
||||||
|
props.noLinks,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ const SmallNote: Component<{ note: PrimalNote, children?: JSXElement, id?: strin
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id={props.id} class={styles.smallNote}>
|
<div id={props.id} class={styles.smallNote} data-note-id={props.note.post.noteId}>
|
||||||
<A href={`/p/${props.note.user.npub}`} class={styles.avatar}>
|
<A href={`/p/${props.note.user.npub}`} class={styles.avatar}>
|
||||||
<Avatar user={props.note.user} size="xxs" />
|
<Avatar user={props.note.user} size="xxs" />
|
||||||
</A>
|
</A>
|
||||||
|
Loading…
Reference in New Issue
Block a user