Compare commits

...

3 Commits

Author SHA1 Message Date
Bojan Mojsilovic d419323f12 Fix article note replies 2024-06-18 14:50:51 +02:00
Bojan Mojsilovic 940baae8a6 Multiple mention render 2024-06-18 14:02:57 +02:00
Bojan Mojsilovic 674ca9d7d7 Link featured user to it's profile 2024-06-18 12:19:34 +02:00
4 changed files with 75 additions and 55 deletions

View File

@ -10,6 +10,7 @@
.userInfo { .userInfo {
display: flex; display: flex;
gap: 8px; gap: 8px;
text-decoration: none;
.userData { .userData {
display: flex; display: flex;

View File

@ -117,7 +117,7 @@ const AuthoreSubscribe: Component<{
fallback={<Loader />} fallback={<Loader />}
> >
<div class={styles.authorSubscribeCard}> <div class={styles.authorSubscribeCard}>
<div class={styles.userInfo}> <A href={`/p/${author()?.npub}`} class={styles.userInfo}>
<Avatar user={author()} size="ml" /> <Avatar user={author()} size="ml" />
<div class={styles.userData}> <div class={styles.userData}>
<div class={styles.userName}> <div class={styles.userName}>
@ -128,7 +128,7 @@ const AuthoreSubscribe: Component<{
{author()?.nip05} {author()?.nip05}
</div> </div>
</div> </div>
</div> </A>
<div class={styles.userPitch}> <div class={styles.userPitch}>
{author()?.about || ''} {author()?.about || ''}
</div> </div>

View File

@ -98,70 +98,85 @@ const account = useAccountContext();
const content = el.innerHTML; const content = el.innerHTML;
const match = content.match(regex); const tokens = content.split(regex);
if (match === null || match.length < 2) return el; let items: any[] = [];
const [nostr, npub] = match; for(let i=0; i<tokens.length; i++) {
const token = tokens[i];
if (npub.startsWith('npub')) {
const other = content.split(nostr); if (token.startsWith('npub')) {
const id = npubToHex(token);
const user = (props.article?.mentionedUsers || {})[id];
const id = npubToHex(npub); items.push(
return (
<p>
<span innerHTML={other[0] || ''}></span>
<Show <Show
when={!props.article?.mentionedUsers || props.article.mentionedUsers[id] !== undefined} when={user}
fallback={<A href={`/p/${npub}`}>{nostr}</A>} fallback={<A href={`/p/${token}`}>nostr:{token}</A>}
> >
<A href={`/p/${npub}`}>@{userName(props.article?.mentionedUsers ? props.article.mentionedUsers[id] : undefined)}</A> <A href={`/p/${token}`}>@{userName(user)}</A>
</Show> </Show>
<span innerHTML={other[1] || ''}></span> );
</p>
);
}
if (npub.startsWith('note')) { continue;
const id = npubToHex(npub);
return (
<Show
when={!props.article?.mentionedNotes || props.article.mentionedNotes[id] !== undefined}
fallback={<A href={`/e/${npub}`}>{nostr}</A>}
>
<div class={styles.embeddedNote}>
<EmbeddedNote
class={styles.embeddedNote}
note={props.article?.mentionedNotes && props.article.mentionedNotes[id]}
mentionedUsers={props.article?.mentionedNotes && props.article.mentionedNotes[id].mentionedUsers || {}}
/>
</div>
</Show>
);
}
if (npub.startsWith('naddr')) {
const mention = props.article?.mentionedNotes && props.article.mentionedNotes[npub];
if (!mention) return el;
const preview = {
url: `/e/${npub}`,
description: (mention.post.tags.find(t => t[0] === 'summary') || [])[1] || mention.post.content.slice(0, 100),
images: [(mention.post.tags.find(t => t[0] === 'image') || [])[1] || mention.user.picture],
title: (mention.post.tags.find(t => t[0] === 'title') || [])[1] || authorName(mention.user),
} }
console.log('MENTION: ', mention) if (token.startsWith('note')) {
return <ArticleLinkPreview const id = npubToHex(token);
preview={preview} const note = (props.article?.mentionedNotes || {})[id];
bordered={true}
/>; items.push(
<Show
when={note}
fallback={<A href={`/e/${token}`}>nostr:{token}</A>}
>
<div class={styles.embeddedNote}>
<EmbeddedNote
class={styles.embeddedNote}
note={note}
mentionedUsers={note.mentionedUsers}
/>
</div>
</Show>
);
continue;
}
if (token.startsWith('naddr')) {
const mention = props.article?.mentionedNotes && props.article.mentionedNotes[token];
if (!mention) {
items.push(<>nostr:{token}</>)
continue;
};
const preview = {
url: `/e/${token}`,
description: (mention.post.tags.find(t => t[0] === 'summary') || [])[1] || mention.post.content.slice(0, 100),
images: [(mention.post.tags.find(t => t[0] === 'image') || [])[1] || mention.user.picture],
title: (mention.post.tags.find(t => t[0] === 'title') || [])[1] || authorName(mention.user),
}
items.push(
<ArticleLinkPreview
preview={preview}
bordered={true}
/>
);
continue;
}
const elem = document.createElement("span");
elem.innerHTML = token;
items.push(<>{elem}</>);
} }
return el; return <p><For each={items}>{item => <>{item}</>}</For></p>;
}; };

View File

@ -715,17 +715,21 @@ const Longform: Component< { naddr: string } > = (props) => {
let id = mention.id; let id = mention.id;
updateStore('page', 'mentions',
(mentions) => ({ ...mentions, [id]: { ...mention } })
);
if (mention.kind === Kind.LongForm) { if (mention.kind === Kind.LongForm) {
id = nip19.naddrEncode({ id = nip19.naddrEncode({
identifier: (mention.tags.find((t: string[]) => t[0] === 'd') || [])[1], identifier: (mention.tags.find((t: string[]) => t[0] === 'd') || [])[1],
pubkey: mention.pubkey, pubkey: mention.pubkey,
kind: mention.kind, kind: mention.kind,
}); });
}
updateStore('page', 'mentions', updateStore('page', 'mentions',
(mentions) => ({ ...mentions, [id]: { ...mention } }) (mentions) => ({ ...mentions, [id]: { ...mention } })
); );
}
return; return;
} }