mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-01 17:31:13 +00:00
Patch small notes in the sidebar to show mentioned users
This commit is contained in:
parent
a0d5463e15
commit
bd0e2410b1
@ -176,7 +176,7 @@ const EmbeddedNote: Component<{ note: PrimalNote, mentionedUsers?: Record<string
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
props.note,
|
props.note,
|
||||||
true,
|
'links',
|
||||||
),
|
),
|
||||||
props.note,
|
props.note,
|
||||||
!props.includeEmbeds,
|
!props.includeEmbeds,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { A } from '@solidjs/router';
|
import { A } from '@solidjs/router';
|
||||||
import { hexToNpub } from '../../lib/keys';
|
import { hexToNpub } from '../../lib/keys';
|
||||||
import { linkPreviews, parseNote1 } from '../../lib/notes';
|
import { linkPreviews, parseNote1, parseNote3 } from '../../lib/notes';
|
||||||
import { truncateNpub, userName } from '../../stores/profile';
|
import { truncateNpub, userName } from '../../stores/profile';
|
||||||
import EmbeddedNote from '../EmbeddedNote/EmbeddedNote';
|
import EmbeddedNote from '../EmbeddedNote/EmbeddedNote';
|
||||||
import {
|
import {
|
||||||
@ -59,7 +59,7 @@ export const parseNoteLinks = (text: string, note: PrimalNote, highlightOnly = f
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const parseNpubLinks = (text: string, note: PrimalNote, highlightOnly = false) => {
|
export const parseNpubLinks = (text: string, note: PrimalNote, highlightOnly?: 'links' | 'text') => {
|
||||||
|
|
||||||
const regex = /\bnostr:((npub|nprofile)1\w+)\b|#\[(\d+)\]/g;
|
const regex = /\bnostr:((npub|nprofile)1\w+)\b|#\[(\d+)\]/g;
|
||||||
|
|
||||||
@ -80,14 +80,16 @@ export const parseNpubLinks = (text: string, note: PrimalNote, highlightOnly = f
|
|||||||
|
|
||||||
const user = note.mentionedUsers && note.mentionedUsers[hex];
|
const user = note.mentionedUsers && note.mentionedUsers[hex];
|
||||||
|
|
||||||
let link = highlightOnly ?
|
const label = user ? userName(user) : truncateNpub(npub);
|
||||||
<span class='linkish'>@{truncateNpub(npub)}</span> :
|
|
||||||
<A href={path}>@{truncateNpub(npub)}</A>;
|
|
||||||
|
|
||||||
if (user) {
|
let link = <span>@{label}</span>;
|
||||||
link = highlightOnly ?
|
|
||||||
<span class='linkish'>@{userName(user)}</span> :
|
if (highlightOnly === 'links') {
|
||||||
MentionedUserLink({ user });
|
link = <span class='linkish'>@{label}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!highlightOnly) {
|
||||||
|
link = user ? <A href={path}>@{label}</A> : MentionedUserLink({ user });
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -99,7 +101,13 @@ export const parseNpubLinks = (text: string, note: PrimalNote, highlightOnly = f
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ParsedNote: Component<{ note: PrimalNote, ignoreMentionedNotes?: boolean, id?: string }> = (props) => {
|
const ParsedNote: Component<{
|
||||||
|
note: PrimalNote,
|
||||||
|
ignoreMentionedNotes?: boolean,
|
||||||
|
id?: string,
|
||||||
|
ignoreMedia?: boolean,
|
||||||
|
noLinks?: 'links' | 'text',
|
||||||
|
}> = (props) => {
|
||||||
|
|
||||||
const media = useMediaContext();
|
const media = useMediaContext();
|
||||||
|
|
||||||
@ -156,12 +164,17 @@ const ParsedNote: Component<{ note: PrimalNote, ignoreMentionedNotes?: boolean,
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const highlightHashtags = (text: string) => {
|
const highlightHashtags = (text: string, noLinks?: 'links' | 'text') => {
|
||||||
const regex = /(?:\s|^)#[^\s!@#$%^&*(),.?":{}|<>]+/ig;
|
const regex = /(?:\s|^)#[^\s!@#$%^&*(),.?":{}|<>]+/ig;
|
||||||
|
|
||||||
return text.replace(regex, (token) => {
|
return text.replace(regex, (token) => {
|
||||||
const [space, term] = token.split('#');
|
const [space, term] = token.split('#');
|
||||||
const embeded = (
|
const embeded = noLinks === 'text' ? (
|
||||||
|
<span>
|
||||||
|
{space}
|
||||||
|
<span>#{term}</span>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
<span>
|
<span>
|
||||||
{space}
|
{space}
|
||||||
<A
|
<A
|
||||||
@ -207,12 +220,29 @@ const ParsedNote: Component<{ note: PrimalNote, ignoreMentionedNotes?: boolean,
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
props.note,
|
props.note,
|
||||||
|
props.noLinks,
|
||||||
),
|
),
|
||||||
props.note,
|
props.note,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [displayedContent, setDisplayedContent] = createSignal<string>(content());
|
const smallContent = () => {
|
||||||
|
return parseNoteLinks(
|
||||||
|
parseNpubLinks(
|
||||||
|
parsedContent(
|
||||||
|
highlightHashtags(
|
||||||
|
props.note.post.content,
|
||||||
|
props.noLinks,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
props.note,
|
||||||
|
props.noLinks,
|
||||||
|
),
|
||||||
|
props.note,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const [displayedContent, setDisplayedContent] = createSignal<string>(props.ignoreMedia ? smallContent() : content());
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
const newContent = replaceLinkPreviews(displayedContent(), { ...linkPreviews });
|
const newContent = replaceLinkPreviews(displayedContent(), { ...linkPreviews });
|
||||||
|
@ -10,6 +10,7 @@ import { authorName } from '../../stores/profile';
|
|||||||
import { note as t } from '../../translations';
|
import { note as t } from '../../translations';
|
||||||
import { useIntl } from '@cookbook/solid-intl';
|
import { useIntl } from '@cookbook/solid-intl';
|
||||||
import { hookForDev } from '../../lib/devTools';
|
import { hookForDev } from '../../lib/devTools';
|
||||||
|
import ParsedNote from '../ParsedNote/ParsedNote';
|
||||||
|
|
||||||
|
|
||||||
const SmallNote: Component<{ note: PrimalNote, children?: JSXElement, id?: string }> = (props) => {
|
const SmallNote: Component<{ note: PrimalNote, children?: JSXElement, id?: string }> = (props) => {
|
||||||
@ -95,7 +96,8 @@ const SmallNote: Component<{ note: PrimalNote, children?: JSXElement, id?: strin
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class={styles.message}>
|
<div class={styles.message}>
|
||||||
<div innerHTML={parsedContent(props.note.post.content)}>
|
<div>
|
||||||
|
<ParsedNote note={props.note} noLinks="text" ignoreMedia={true} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</A>
|
</A>
|
||||||
|
Loading…
Reference in New Issue
Block a user