diff --git a/src/shared/notes/users/mini.tsx b/src/shared/notes/users/mini.tsx
deleted file mode 100644
index 6fa5d477..00000000
--- a/src/shared/notes/users/mini.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import { Image } from '@shared/image';
-
-import { useProfile } from '@utils/hooks/useProfile';
-
-export function MiniUser({ pubkey }: { pubkey: string }) {
- const { status, user } = useProfile(pubkey);
-
- if (status === 'loading') {
- return
;
- }
-
- return (
-
- );
-}
diff --git a/src/shared/notes/users/repost.tsx b/src/shared/notes/users/repost.tsx
deleted file mode 100644
index b84757ea..00000000
--- a/src/shared/notes/users/repost.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-import { Image } from '@shared/image';
-
-import { useProfile } from '@utils/hooks/useProfile';
-import { shortenKey } from '@utils/shortenKey';
-
-export function RepostUser({ pubkey }: { pubkey: string }) {
- const { status, user } = useProfile(pubkey);
-
- if (status === 'loading') {
- return
;
- }
-
- return (
-
-
-
-
- {user?.name || user?.display_name || shortenKey(pubkey)}
-
- reposted
-
-
- );
-}
diff --git a/src/shared/notes/users/thread.tsx b/src/shared/notes/users/thread.tsx
deleted file mode 100644
index 7f908d97..00000000
--- a/src/shared/notes/users/thread.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import { Image } from '@shared/image';
-
-import { formatCreatedAt } from '@utils/createdAt';
-import { useProfile } from '@utils/hooks/useProfile';
-import { displayNpub } from '@utils/shortenKey';
-
-export function ThreadUser({ pubkey, time }: { pubkey: string; time: number }) {
- const { status, user } = useProfile(pubkey);
- const createdAt = formatCreatedAt(time);
-
- if (status === 'loading') {
- return
;
- }
-
- return (
-
-
-
-
- {user.display_name || user.name}
-
-
- {createdAt}
- ·
- {displayNpub(pubkey, 16)}
-
-
-
- );
-}
diff --git a/src/shared/user.tsx b/src/shared/user.tsx
index fe8c3b4b..46587eb8 100644
--- a/src/shared/user.tsx
+++ b/src/shared/user.tsx
@@ -1,7 +1,8 @@
import * as Popover from '@radix-ui/react-popover';
+import { memo } from 'react';
import { Link } from 'react-router-dom';
-import { twMerge } from 'tailwind-merge';
+import { WorldIcon } from '@shared/icons';
import { Image } from '@shared/image';
import { NIP05 } from '@shared/nip05';
@@ -9,77 +10,172 @@ import { formatCreatedAt } from '@utils/createdAt';
import { useProfile } from '@utils/hooks/useProfile';
import { displayNpub } from '@utils/shortenKey';
-export function User({
+export const User = memo(function User({
pubkey,
time,
- size,
- isRepost = false,
- isChat = false,
+ variant = 'default',
+ embedProfile,
}: {
pubkey: string;
- time: number;
- size?: string;
- isRepost?: boolean;
- isChat?: boolean;
+ time?: number;
+ variant?: 'default' | 'simple' | 'mention' | 'repost' | 'chat' | 'large' | 'thread';
+ embedProfile?: string;
}) {
- const { status, user } = useProfile(pubkey);
-
- const createdAt = formatCreatedAt(time, isChat);
- const avatarWidth = size === 'small' ? 'w-6' : 'w-11';
- const avatarHeight = size === 'small' ? 'h-6' : 'h-11';
+ const { status, user } = useProfile(pubkey, embedProfile);
+ const createdAt = time ? formatCreatedAt(time, variant === 'chat') : 0;
if (status === 'loading') {
- return (
-
-
-
+ if (variant === 'mention') {
+ return (
+
+ );
+ }
+
+ return (
+
+ );
+ }
+
+ if (variant === 'mention') {
+ return (
+
+
+
+
+ {user?.display_name || user?.name || displayNpub(pubkey, 16)}
+
+ ·
+ {createdAt}
+
+
+ );
+ }
+
+ if (variant === 'large') {
+ return (
+
+
+
+
+
+ {user?.name || user?.display_name}
+
+
+ {user?.about || user?.bio || 'No bio'}
+
+
+
+ {user?.website ? (
+
+
+
{user.website}
+
+ ) : null}
+
+
+
+ );
+ }
+
+ if (variant === 'simple') {
+ return (
+
+
+
+
+ {user?.name || user?.display_name}
+
+
+ {user?.nip05 || user?.username || displayNpub(pubkey, 16)}
+
+
+
+ );
+ }
+
+ if (variant === 'repost') {
+ return (
+
+
+
+
+ {user?.display_name || user?.name || displayNpub(pubkey, 16)}
+
+ reposted
+ ·
+ {createdAt}
+
+
+ );
+ }
+
+ if (variant === 'thread') {
+ return (
+
+
+
+
+ {user?.display_name || user?.name}
+
+
+ {createdAt}
+ ·
+ {displayNpub(pubkey, 16)}
+
+
);
}
return (
-
+
-
-
+
+
{user?.display_name || user?.name || displayNpub(pubkey, 16)}
·
@@ -139,4 +235,4 @@ export function User({
);
-}
+});
diff --git a/src/shared/widgets/local/thread.tsx b/src/shared/widgets/local/thread.tsx
index 6087e129..1d754610 100644
--- a/src/shared/widgets/local/thread.tsx
+++ b/src/shared/widgets/local/thread.tsx
@@ -10,12 +10,12 @@ import {
NoteReplyForm,
NoteStats,
TextNote,
- ThreadUser,
UnknownNote,
} from '@shared/notes';
import { RepliesList } from '@shared/notes/replies/list';
import { NoteSkeleton } from '@shared/notes/skeleton';
import { TitleBar } from '@shared/titleBar';
+import { User } from '@shared/user';
import { useEvent } from '@utils/hooks/useEvent';
import { Widget } from '@utils/types';
@@ -53,7 +53,7 @@ export function LocalThreadWidget({ params }: { params: Widget }) {
) : (
-
+
{renderKind(data)}
toggleGroup(item)}
className="inline-flex transform items-center justify-between px-4 py-2 hover:bg-white/20"
>
-
+
{groups.includes(item) && (
diff --git a/src/utils/hooks/useEvent.ts b/src/utils/hooks/useEvent.ts
index d88102dd..77b706e2 100644
--- a/src/utils/hooks/useEvent.ts
+++ b/src/utils/hooks/useEvent.ts
@@ -25,6 +25,7 @@ export function useEvent(
authors: [naddr.pubkey],
});
const rEvent = [...rEvents].slice(-1)[0];
+ if (!rEvent) return Promise.reject(new Error('event not found'));
return rEvent;
}
@@ -40,7 +41,7 @@ export function useEvent(
// get event from relay if event in db not present
const event = await ndk.fetchEvent(id);
- if (!event) throw new Error(`Event not found: ${id}`);
+ if (!event) return Promise.reject(new Error('event not found'));
const rawEvent = toRawEvent(event);
await db.createEvent(rawEvent);