diff --git a/src/app/browse/index.tsx b/src/app/browse/index.tsx
index 3f095f29..cb538e5e 100644
--- a/src/app/browse/index.tsx
+++ b/src/app/browse/index.tsx
@@ -13,7 +13,7 @@ export function BrowseScreen() {
to="/browse/"
className={({ isActive }) =>
twMerge(
- 'inline-flex h-8 w-20 items-center justify-center rounded-full text-sm font-semibold',
+ 'inline-flex h-7 w-20 items-center justify-center rounded-full text-sm font-semibold',
isActive ? 'bg-white/10 hover:bg-white/20' : ' hover:bg-white/5'
)
}
@@ -24,7 +24,7 @@ export function BrowseScreen() {
to="/browse/relays"
className={({ isActive }) =>
twMerge(
- 'inline-flex h-8 w-20 items-center justify-center rounded-full text-sm font-semibold',
+ 'inline-flex h-7 w-20 items-center justify-center rounded-full text-sm font-semibold',
isActive ? 'bg-white/10 hover:bg-white/20' : ' hover:bg-white/5'
)
}
diff --git a/src/app/browse/relays.tsx b/src/app/browse/relays.tsx
index 203a142e..6047990b 100644
--- a/src/app/browse/relays.tsx
+++ b/src/app/browse/relays.tsx
@@ -1,7 +1,12 @@
export function BrowseRelaysScreen() {
return (
-
-
TODO
+
);
}
diff --git a/src/app/chats/components/list.tsx b/src/app/chats/components/list.tsx
index 86fbccf7..8335b7b5 100644
--- a/src/app/chats/components/list.tsx
+++ b/src/app/chats/components/list.tsx
@@ -7,6 +7,8 @@ import { UnknownsModal } from '@app/chats/components/unknowns';
import { useStorage } from '@libs/storage/provider';
+import { LoaderIcon } from '@shared/icons';
+
import { useNostr } from '@utils/hooks/useNostr';
export function ChatsList() {
@@ -33,8 +35,10 @@ export function ChatsList() {
return (
-
-
+
+
+
+
Loading messages...
);
diff --git a/src/app/chats/components/messages/item.tsx b/src/app/chats/components/messages/item.tsx
index 0455e511..94abb01f 100644
--- a/src/app/chats/components/messages/item.tsx
+++ b/src/app/chats/components/messages/item.tsx
@@ -2,6 +2,7 @@ import { NDKEvent } from '@nostr-dev-kit/ndk';
import { useDecryptMessage } from '@app/chats/hooks/useDecryptMessage';
+import { TextNote } from '@shared/notes';
import { User } from '@shared/user';
export function ChatMessageItem({
@@ -20,13 +21,12 @@ export function ChatMessageItem({
}
return (
-
+
-
-
- {message.content}
-
+
diff --git a/src/app/chats/index.tsx b/src/app/chats/index.tsx
index 2076e382..c4bd0dd7 100644
--- a/src/app/chats/index.tsx
+++ b/src/app/chats/index.tsx
@@ -1,8 +1,8 @@
-import { NDKSubscription } from '@nostr-dev-kit/ndk';
+import { NDKEvent, NDKSubscription } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
import { useCallback, useEffect, useRef } from 'react';
import { useParams } from 'react-router-dom';
-import { Virtuoso } from 'react-virtuoso';
+import { VList, VListHandle } from 'virtua';
import { ChatMessageForm } from '@app/chats/components/messages/form';
import { ChatMessageItem } from '@app/chats/components/messages/item';
@@ -18,7 +18,7 @@ import { useStronghold } from '@stores/stronghold';
import { useNostr } from '@utils/hooks/useNostr';
export function ChatScreen() {
- const virtuosoRef = useRef(null);
+ const listRef = useRef
(null);
const userPrivkey = useStronghold((state) => state.privkey);
const { db } = useStorage();
@@ -29,10 +29,8 @@ export function ChatScreen() {
return await fetchNIP04Messages(pubkey);
});
- const itemContent = useCallback(
- (index: string | number) => {
- const message = data[index];
- if (!message) return;
+ const renderItem = useCallback(
+ (message: NDKEvent) => {
return (
{
- return data[index].id;
- },
- [data]
- );
+ useEffect(() => {
+ if (data.length > 0) listRef.current?.scrollToIndex(data.length);
+ }, [data]);
useEffect(() => {
const sub: NDKSubscription = ndk.subscribe(
@@ -86,22 +81,17 @@ export function ChatScreen() {
Loading messages
+ ) : data.length === 0 ? (
+
+
🙌
+
+ You two didn't talk yet, let's send first message
+
+
) : (
-
Empty,
- }}
- />
+
+ {data.map((message) => renderItem(message))}
+
)}
@@ -120,12 +110,3 @@ export function ChatScreen() {
);
}
-
-const Empty = (
-
-
🙌
-
- You two didn't talk yet, let's send first message
-
-
-);
diff --git a/src/app/users/index.tsx b/src/app/users/index.tsx
index d05a53ba..12bc7973 100644
--- a/src/app/users/index.tsx
+++ b/src/app/users/index.tsx
@@ -1,8 +1,8 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
-import { useVirtualizer } from '@tanstack/react-virtual';
-import { useCallback, useRef } from 'react';
+import { useCallback } from 'react';
import { useParams } from 'react-router-dom';
+import { VList } from 'virtua';
import { UserProfile } from '@app/users/components/profile';
@@ -32,79 +32,35 @@ export function UserScreen() {
return [...events] as unknown as NDKEvent[];
});
- const parentRef = useRef();
- const virtualizer = useVirtualizer({
- count: data ? data.length : 0,
- getScrollElement: () => parentRef.current,
- estimateSize: () => 650,
- overscan: 4,
- });
- const items = virtualizer.getVirtualItems();
-
// render event match event kind
const renderItem = useCallback(
- (index: string | number) => {
- const event: NDKEvent = data[index];
- if (!event) return;
-
+ (event: NDKEvent) => {
switch (event.kind) {
case NDKKind.Text:
return (
-
-
-
-
-
+
+
+
);
case NDKKind.Repost:
- return (
-
-
-
- );
+ return
;
case 1063:
return (
-
-
-
-
-
+
+
+
);
case NDKKind.Article:
return (
-
+
+
+
);
default:
return (
-
-
-
-
-
+
+
+
);
}
},
@@ -112,10 +68,7 @@ export function UserScreen() {
);
return (
-
+
@@ -129,7 +82,7 @@ export function UserScreen() {
- ) : items.length === 0 ? (
+ ) : data.length === 0 ? (
@@ -140,22 +93,10 @@ export function UserScreen() {
) : (
-
-
- {items.map((item) => renderItem(item.index))}
-
-
+
+ {data.map((item) => renderItem(item))}
+
+
)}
diff --git a/src/libs/ndk/instance.ts b/src/libs/ndk/instance.ts
index d8306f91..01709c76 100644
--- a/src/libs/ndk/instance.ts
+++ b/src/libs/ndk/instance.ts
@@ -21,6 +21,7 @@ export const NDKInstance = () => {
);
// TODO: fully support NIP-11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getExplicitRelays() {
try {
// get relays
@@ -62,7 +63,7 @@ export const NDKInstance = () => {
}
async function initNDK() {
- const explicitRelayUrls = await getExplicitRelays();
+ const explicitRelayUrls = await db.getExplicitRelayUrls();
const instance = new NDK({
explicitRelayUrls,
cacheAdapter,
diff --git a/src/shared/navigation.tsx b/src/shared/navigation.tsx
index 2844924f..4fd9029e 100644
--- a/src/shared/navigation.tsx
+++ b/src/shared/navigation.tsx
@@ -23,7 +23,10 @@ export function Navigation() {
]);
return (
-
+
{
- const title = event.tags.find((tag) => tag[0] === 'title')?.[1];
- const image = event.tags.find((tag) => tag[0] === 'image')?.[1];
- const summary = event.tags.find((tag) => tag[0] === 'summary')?.[1];
+ const title = props.event.tags.find((tag) => tag[0] === 'title')?.[1];
+ const image = props.event.tags.find((tag) => tag[0] === 'image')?.[1];
+ const summary = props.event.tags.find((tag) => tag[0] === 'summary')?.[1];
- let publishedAt: Date | string | number = event.tags.find(
+ let publishedAt: Date | string | number = props.event.tags.find(
(tag) => tag[0] === 'published_at'
)?.[1];
if (publishedAt) {
publishedAt = new Date(parseInt(publishedAt)).toLocaleDateString('en-US');
} else {
- publishedAt = new Date(event.created_at * 1000).toLocaleDateString('en-US');
+ publishedAt = new Date(props.event.created_at * 1000).toLocaleDateString('en-US');
}
return {
@@ -25,11 +25,11 @@ export function ArticleNote({ event }: { event: NDKEvent }) {
publishedAt,
summary,
};
- }, [event.id]);
+ }, [props.event.id]);
return (
diff --git a/src/shared/notes/kinds/file.tsx b/src/shared/notes/kinds/file.tsx
index 7df8a3c3..9595338f 100644
--- a/src/shared/notes/kinds/file.tsx
+++ b/src/shared/notes/kinds/file.tsx
@@ -6,8 +6,8 @@ import { Image } from '@shared/image';
import { fileType } from '@utils/nip94';
-export function FileNote({ event }: { event: NDKEvent }) {
- const url = event.tags.find((el) => el[0] === 'url')[1];
+export function FileNote(props: { event?: NDKEvent }) {
+ const url = props.event.tags.find((el) => el[0] === 'url')[1];
const type = fileType(url);
if (type === 'image') {
@@ -15,7 +15,7 @@ export function FileNote({ event }: { event: NDKEvent }) {
diff --git a/src/shared/notes/kinds/text.tsx b/src/shared/notes/kinds/text.tsx
index 6064f073..a572c082 100644
--- a/src/shared/notes/kinds/text.tsx
+++ b/src/shared/notes/kinds/text.tsx
@@ -13,8 +13,8 @@ import {
import { parser } from '@utils/parser';
-export function TextNote({ content }: { content: string }) {
- const richContent = parser(content) ?? null;
+export function TextNote(props: { content?: string }) {
+ const richContent = parser(props.content) ?? null;
if (!richContent) {
return (
@@ -26,7 +26,7 @@ export function TextNote({ content }: { content: string }) {
unwrapDisallowed={true}
linkTarget={'_blank'}
>
- {content}
+ {props.content}
);
diff --git a/src/shared/notes/kinds/unknown.tsx b/src/shared/notes/kinds/unknown.tsx
index 243e244d..0be00b35 100644
--- a/src/shared/notes/kinds/unknown.tsx
+++ b/src/shared/notes/kinds/unknown.tsx
@@ -1,18 +1,18 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
-export function UnknownNote({ event }: { event: NDKEvent }) {
+export function UnknownNote(props: { event?: NDKEvent }) {
return (
- Unknown kind: {event.kind}
+ Unknown kind: {props.event.kind}
Lume isn't fully support this kind
-
{event.content.toString()}
+
{props.event.content.toString()}
);
diff --git a/src/shared/notes/replies/sub.tsx b/src/shared/notes/replies/sub.tsx
index 004aa474..e98b88f3 100644
--- a/src/shared/notes/replies/sub.tsx
+++ b/src/shared/notes/replies/sub.tsx
@@ -10,7 +10,7 @@ export function SubReply({ event }: { event: NDKEvent }) {
diff --git a/src/shared/notes/wrapper.tsx b/src/shared/notes/wrapper.tsx
index 3d6ff4ce..5fb5b38f 100644
--- a/src/shared/notes/wrapper.tsx
+++ b/src/shared/notes/wrapper.tsx
@@ -1,5 +1,5 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
-import { ReactNode } from 'react';
+import { ReactElement, cloneElement } from 'react';
import { twMerge } from 'tailwind-merge';
import { ChildNote, NoteActions } from '@shared/notes';
@@ -13,7 +13,7 @@ export function NoteWrapper({
lighter = false,
}: {
event: NDKEvent;
- children: ReactNode;
+ children: ReactElement;
repost?: boolean;
root?: string;
reply?: string;
@@ -34,7 +34,10 @@ export function NoteWrapper({
- {children}
+ {cloneElement(
+ children,
+ event.kind === 1 ? { content: event.content } : { event: event }
+ )}
diff --git a/src/shared/widgets/global/articles.tsx b/src/shared/widgets/global/articles.tsx
index fa19b01f..a303e818 100644
--- a/src/shared/widgets/global/articles.tsx
+++ b/src/shared/widgets/global/articles.tsx
@@ -1,7 +1,7 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
-import { useVirtualizer } from '@tanstack/react-virtual';
-import { useCallback, useRef } from 'react';
+import { useCallback } from 'react';
+import { VList } from 'virtua';
import { useNDK } from '@libs/ndk/provider';
@@ -25,27 +25,13 @@ export function GlobalArticlesWidget({ params }: { params: Widget }) {
{ refetchOnWindowFocus: false }
);
- const parentRef = useRef
(null);
- const virtualizer = useVirtualizer({
- count: data ? data.length : 0,
- getScrollElement: () => parentRef.current,
- estimateSize: () => 650,
- overscan: 4,
- });
- const items = virtualizer.getVirtualItems();
-
// render event match event kind
const renderItem = useCallback(
- (index: string | number) => {
- const event: NDKEvent = data[index];
- if (!event) return;
-
+ (event: NDKEvent) => {
return (
-
+
+
+
);
},
[data]
@@ -54,40 +40,32 @@ export function GlobalArticlesWidget({ params }: { params: Widget }) {
return (
-
+
{status === 'loading' ? (
- ) : items.length === 0 ? (
-
-
-
-
- There have been no new articles in the last 24 hours.
+ ) : data.length === 0 ? (
+
+
+
+
+
+ Your newsfeed is empty
+
+
+ Connect more people to explore more content
) : (
-
-
- {items.map((item) => renderItem(item.index))}
-
-
+
+ {data.map((item) => renderItem(item))}
+
+
)}
diff --git a/src/shared/widgets/global/files.tsx b/src/shared/widgets/global/files.tsx
index 56011e19..f6ce8c91 100644
--- a/src/shared/widgets/global/files.tsx
+++ b/src/shared/widgets/global/files.tsx
@@ -1,7 +1,7 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
-import { useVirtualizer } from '@tanstack/react-virtual';
-import { useCallback, useRef } from 'react';
+import { useCallback } from 'react';
+import { VList } from 'virtua';
import { useNDK } from '@libs/ndk/provider';
@@ -26,27 +26,13 @@ export function GlobalFilesWidget({ params }: { params: Widget }) {
{ refetchOnWindowFocus: false }
);
- const parentRef = useRef
(null);
- const virtualizer = useVirtualizer({
- count: data ? data.length : 0,
- getScrollElement: () => parentRef.current,
- estimateSize: () => 650,
- overscan: 4,
- });
- const items = virtualizer.getVirtualItems();
-
// render event match event kind
const renderItem = useCallback(
- (index: string | number) => {
- const event: NDKEvent = data[index];
- if (!event) return;
-
+ (event: NDKEvent) => {
return (
-
-
-
-
-
+
+
+
);
},
[data]
@@ -55,40 +41,32 @@ export function GlobalFilesWidget({ params }: { params: Widget }) {
return (
-
+
{status === 'loading' ? (
- ) : items.length === 0 ? (
-
-
-
-
- There have been no new files in the last 24 hours.
+ ) : data.length === 0 ? (
+
+
+
+
+
+ Your newsfeed is empty
+
+
+ Connect more people to explore more content
) : (
-
-
- {items.map((item) => renderItem(item.index))}
-
-
+
+ {data.map((item) => renderItem(item))}
+
+
)}
diff --git a/src/shared/widgets/global/hashtag.tsx b/src/shared/widgets/global/hashtag.tsx
index 374b87c0..60e828de 100644
--- a/src/shared/widgets/global/hashtag.tsx
+++ b/src/shared/widgets/global/hashtag.tsx
@@ -1,7 +1,7 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
-import { useVirtualizer } from '@tanstack/react-virtual';
-import { useCallback, useRef } from 'react';
+import { useCallback } from 'react';
+import { VList } from 'virtua';
import { useNDK } from '@libs/ndk/provider';
@@ -35,79 +35,35 @@ export function GlobalHashtagWidget({ params }: { params: Widget }) {
{ refetchOnWindowFocus: false }
);
- const parentRef = useRef
(null);
- const virtualizer = useVirtualizer({
- count: data ? data.length : 0,
- getScrollElement: () => parentRef.current,
- estimateSize: () => 650,
- overscan: 4,
- });
- const items = virtualizer.getVirtualItems();
-
// render event match event kind
const renderItem = useCallback(
- (index: string | number) => {
- const event: NDKEvent = data[index];
- if (!event) return;
-
+ (event: NDKEvent) => {
switch (event.kind) {
case NDKKind.Text:
return (
-
-
-
-
-
+
+
+
);
case NDKKind.Repost:
- return (
-
-
-
- );
+ return ;
case 1063:
return (
-
-
-
-
-
+
+
+
);
case NDKKind.Article:
return (
-
+
+
+
);
default:
return (
-
-
-
-
-
+
+
+
);
}
},
@@ -117,40 +73,33 @@ export function GlobalHashtagWidget({ params }: { params: Widget }) {
return (
-
+
{status === 'loading' ? (
- ) : items.length === 0 ? (
-
-
-
-
- There have been no new posts with this hashtag in the last 24 hours.
+ ) : data.length === 0 ? (
+
+
+
+
+
+ Your newsfeed is empty
+
+
+ Connect more people to explore more content
) : (
-
-
- {items.map((item) => renderItem(item.index))}
-
-
+
+ {data.map((item) => renderItem(item))}
+
+
+
)}
diff --git a/src/shared/widgets/local/articles.tsx b/src/shared/widgets/local/articles.tsx
index fd49fc1e..035112bc 100644
--- a/src/shared/widgets/local/articles.tsx
+++ b/src/shared/widgets/local/articles.tsx
@@ -1,7 +1,7 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useInfiniteQuery } from '@tanstack/react-query';
-import { useVirtualizer } from '@tanstack/react-virtual';
-import { useCallback, useMemo, useRef } from 'react';
+import { useCallback, useMemo } from 'react';
+import { VList } from 'virtua';
import { useStorage } from '@libs/storage/provider';
@@ -27,27 +27,15 @@ export function LocalArticlesWidget({ params }: { params: Widget }) {
() => (data ? data.pages.flatMap((d: { data: DBEvent[] }) => d.data) : []),
[data]
);
- const parentRef = useRef
();
- const virtualizer = useVirtualizer({
- count: hasNextPage ? dbEvents.length : dbEvents.length,
- getScrollElement: () => parentRef.current,
- estimateSize: () => 650,
- overscan: 4,
- });
- const items = virtualizer.getVirtualItems();
// render event match event kind
const renderItem = useCallback(
- (index: string | number) => {
- const event: NDKEvent = data[index];
- if (!event) return;
-
+ (dbEvent: DBEvent) => {
+ const event: NDKEvent = JSON.parse(dbEvent.event as string);
return (
-
-
-
-
-
+
+
+
);
},
[data]
@@ -56,75 +44,59 @@ export function LocalArticlesWidget({ params }: { params: Widget }) {
return (
-
+
{status === 'loading' ? (
- ) : items.length === 0 ? (
-
-
-
-
- There have been no new posts.
+ ) : dbEvents.length === 0 ? (
+
+
+
+
+
+ Your newsfeed is empty
+
+
+ Connect more people to explore more content
) : (
-
-
- {items.map((item) => renderItem(item.index))}
+
+ {dbEvents.map((item) => renderItem(item))}
+
+ {dbEvents.length > 0 ? (
+
+ ) : null}
-
+
+
)}
- {isFetchingNextPage && (
-
- )}
-
-
-
);
diff --git a/src/shared/widgets/local/feeds.tsx b/src/shared/widgets/local/feeds.tsx
index 23a4bf9a..5f0afa2e 100644
--- a/src/shared/widgets/local/feeds.tsx
+++ b/src/shared/widgets/local/feeds.tsx
@@ -1,7 +1,7 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useInfiniteQuery } from '@tanstack/react-query';
-import { useVirtualizer } from '@tanstack/react-virtual';
-import { useCallback, useMemo, useRef } from 'react';
+import { useCallback, useMemo } from 'react';
+import { VList } from 'virtua';
import { useStorage } from '@libs/storage/provider';
@@ -36,80 +36,42 @@ export function LocalFeedsWidget({ params }: { params: Widget }) {
() => (data ? data.pages.flatMap((d: { data: DBEvent[] }) => d.data) : []),
[data]
);
- const parentRef = useRef
();
- const virtualizer = useVirtualizer({
- count: hasNextPage ? dbEvents.length : dbEvents.length,
- getScrollElement: () => parentRef.current,
- estimateSize: () => 650,
- overscan: 4,
- });
- const items = virtualizer.getVirtualItems();
// render event match event kind
const renderItem = useCallback(
- (index: string | number) => {
- const dbEvent: DBEvent = dbEvents[index];
- if (!dbEvent) return;
-
+ (dbEvent: DBEvent) => {
const event: NDKEvent = JSON.parse(dbEvent.event as string);
switch (event.kind) {
case NDKKind.Text:
return (
-
-
-
-
-
+
+
);
case NDKKind.Repost:
- return (
-
-
-
- );
+ return ;
case 1063:
return (
-
-
-
-
-
+
+
+
);
case NDKKind.Article:
return (
-
+
+
+
);
default:
return (
-
-
-
-
-
+
+
+
);
}
},
@@ -119,75 +81,59 @@ export function LocalFeedsWidget({ params }: { params: Widget }) {
return (
-
+
{status === 'loading' ? (
- ) : items.length === 0 ? (
-
-
-
-
- There have been no new posts.
+ ) : dbEvents.length === 0 ? (
+
+
+
+
+
+ Your newsfeed is empty
+
+
+ Connect more people to explore more content
) : (
-
-
- {items.map((item) => renderItem(item.index))}
+
+ {dbEvents.map((item) => renderItem(item))}
+
+ {dbEvents.length > 0 ? (
+
+ ) : null}
-
+
+
)}
- {isFetchingNextPage && (
-
- )}
-
-
-
);
diff --git a/src/shared/widgets/local/files.tsx b/src/shared/widgets/local/files.tsx
index d8328cc0..3282e753 100644
--- a/src/shared/widgets/local/files.tsx
+++ b/src/shared/widgets/local/files.tsx
@@ -1,7 +1,7 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { useInfiniteQuery } from '@tanstack/react-query';
-import { useVirtualizer } from '@tanstack/react-virtual';
-import { useCallback, useMemo, useRef } from 'react';
+import { useCallback, useMemo } from 'react';
+import { VList } from 'virtua';
import { useStorage } from '@libs/storage/provider';
@@ -27,27 +27,15 @@ export function LocalFilesWidget({ params }: { params: Widget }) {
() => (data ? data.pages.flatMap((d: { data: DBEvent[] }) => d.data) : []),
[data]
);
- const parentRef = useRef
();
- const virtualizer = useVirtualizer({
- count: hasNextPage ? dbEvents.length : dbEvents.length,
- getScrollElement: () => parentRef.current,
- estimateSize: () => 650,
- overscan: 4,
- });
- const items = virtualizer.getVirtualItems();
// render event match event kind
const renderItem = useCallback(
- (index: string | number) => {
- const event: NDKEvent = data[index];
- if (!event) return;
-
+ (dbEvent: DBEvent) => {
+ const event: NDKEvent = JSON.parse(dbEvent.event as string);
return (
-
-
-
-
-
+
+
+
);
},
[data]
@@ -56,75 +44,59 @@ export function LocalFilesWidget({ params }: { params: Widget }) {
return (
-
+
{status === 'loading' ? (
- ) : items.length === 0 ? (
-
-
-
-
- There have been no new posts.
+ ) : dbEvents.length === 0 ? (
+
+
+
+
+
+ Your newsfeed is empty
+
+
+ Connect more people to explore more content
) : (
-
-
- {items.map((item) => renderItem(item.index))}
+
+ {dbEvents.map((item) => renderItem(item))}
+
+ {dbEvents.length > 0 ? (
+
+ ) : null}
-
+
+
)}
- {isFetchingNextPage && (
-
- )}
-
-
-
);
diff --git a/src/shared/widgets/local/follows.tsx b/src/shared/widgets/local/follows.tsx
index 0d22b0f8..4f56762e 100644
--- a/src/shared/widgets/local/follows.tsx
+++ b/src/shared/widgets/local/follows.tsx
@@ -1,7 +1,7 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useInfiniteQuery } from '@tanstack/react-query';
-import { useVirtualizer } from '@tanstack/react-virtual';
-import { useCallback, useMemo, useRef } from 'react';
+import { useCallback, useMemo } from 'react';
+import { VList } from 'virtua';
import { useStorage } from '@libs/storage/provider';
@@ -35,80 +35,42 @@ export function LocalFollowsWidget({ params }: { params: Widget }) {
() => (data ? data.pages.flatMap((d: { data: DBEvent[] }) => d.data) : []),
[data]
);
- const parentRef = useRef
();
- const virtualizer = useVirtualizer({
- count: hasNextPage ? dbEvents.length : dbEvents.length,
- getScrollElement: () => parentRef.current,
- estimateSize: () => 650,
- overscan: 4,
- });
- const items = virtualizer.getVirtualItems();
// render event match event kind
const renderItem = useCallback(
- (index: string | number) => {
- const dbEvent: DBEvent = dbEvents[index];
- if (!dbEvent) return;
-
+ (dbEvent: DBEvent) => {
const event: NDKEvent = JSON.parse(dbEvent.event as string);
switch (event.kind) {
case NDKKind.Text:
return (
-
-
-
-
-
+
+
);
case NDKKind.Repost:
- return (
-
-
-
- );
+ return ;
case 1063:
return (
-
-
-
-
-
+
+
+
);
case NDKKind.Article:
return (
-
+
+
+
);
default:
return (
-
-
-
-
-
+
+
+
);
}
},
@@ -118,7 +80,7 @@ export function LocalFollowsWidget({ params }: { params: Widget }) {
return (
-
+
{status === 'loading' ? (
@@ -140,59 +102,37 @@ export function LocalFollowsWidget({ params }: { params: Widget }) {
) : (
-
-
- {items.map((item) => renderItem(item.index))}
+
+ {dbEvents.map((item) => renderItem(item))}
+
+ {dbEvents.length > 0 ? (
+
+ ) : null}
-
+
+
)}
- {isFetchingNextPage && (
-
- )}
-
- {dbEvents.length > 0 ? (
-
- ) : null}
-
);
diff --git a/src/shared/widgets/local/network.tsx b/src/shared/widgets/local/network.tsx
index 61e8c213..e0938d5f 100644
--- a/src/shared/widgets/local/network.tsx
+++ b/src/shared/widgets/local/network.tsx
@@ -1,7 +1,7 @@
import { NDKEvent, NDKFilter, NDKKind } from '@nostr-dev-kit/ndk';
import { useInfiniteQuery } from '@tanstack/react-query';
-import { useVirtualizer } from '@tanstack/react-virtual';
-import { useCallback, useEffect, useMemo, useRef } from 'react';
+import { useCallback, useEffect, useMemo } from 'react';
+import { VList } from 'virtua';
import { useStorage } from '@libs/storage/provider';
@@ -38,80 +38,42 @@ export function LocalNetworkWidget() {
() => (data ? data.pages.flatMap((d: { data: DBEvent[] }) => d.data) : []),
[data]
);
- const parentRef = useRef
();
- const virtualizer = useVirtualizer({
- count: hasNextPage ? dbEvents.length : dbEvents.length,
- getScrollElement: () => parentRef.current,
- estimateSize: () => 650,
- overscan: 4,
- });
- const items = virtualizer.getVirtualItems();
// render event match event kind
const renderItem = useCallback(
- (index: string | number) => {
- const dbEvent: DBEvent = dbEvents[index];
- if (!dbEvent) return;
-
+ (dbEvent: DBEvent) => {
const event: NDKEvent = JSON.parse(dbEvent.event as string);
switch (event.kind) {
case NDKKind.Text:
return (
-
-
-
-
-
+
+
);
case NDKKind.Repost:
- return (
-
-
-
- );
+ return ;
case 1063:
return (
-
-
-
-
-
+
+
+
);
case NDKKind.Article:
return (
-
+
+
+
);
default:
return (
-
-
-
-
-
+
+
+
);
}
},
@@ -125,7 +87,7 @@ export function LocalNetworkWidget() {
const filter: NDKFilter = {
kinds: [NDKKind.Text, NDKKind.Repost],
authors: db.account.network,
- since: db.account.last_login_at ?? Math.floor(Date.now() / 1000),
+ since: Math.floor(Date.now() / 1000),
};
sub(filter, async (event) => {
@@ -138,7 +100,7 @@ export function LocalNetworkWidget() {
return (
-
+
{status === 'loading' ? (
@@ -160,59 +122,37 @@ export function LocalNetworkWidget() {
) : (
-
-
- {items.map((item) => renderItem(item.index))}
+
+ {dbEvents.map((item) => renderItem(item))}
+
+ {dbEvents.length > 0 ? (
+
+ ) : null}
-
+
+
)}
- {isFetchingNextPage && (
-
- )}
-
- {dbEvents.length > 0 ? (
-
- ) : null}
-
);
diff --git a/src/shared/widgets/local/user.tsx b/src/shared/widgets/local/user.tsx
index fc920bc9..682339be 100644
--- a/src/shared/widgets/local/user.tsx
+++ b/src/shared/widgets/local/user.tsx
@@ -1,7 +1,7 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
-import { useVirtualizer } from '@tanstack/react-virtual';
-import { useCallback, useRef } from 'react';
+import { useCallback } from 'react';
+import { VList } from 'virtua';
import { useNDK } from '@libs/ndk/provider';
@@ -41,79 +41,35 @@ export function LocalUserWidget({ params }: { params: Widget }) {
}
);
- const parentRef = useRef
(null);
- const virtualizer = useVirtualizer({
- count: data ? data.length : 0,
- getScrollElement: () => parentRef.current,
- estimateSize: () => 650,
- overscan: 4,
- });
- const items = virtualizer.getVirtualItems();
-
// render event match event kind
const renderItem = useCallback(
- (index: string | number) => {
- const event: NDKEvent = data[index];
- if (!event) return;
-
+ (event: NDKEvent) => {
switch (event.kind) {
case NDKKind.Text:
return (
-
-
-
-
-
+
+
+
);
case NDKKind.Repost:
- return (
-
-
-
- );
+ return ;
case 1063:
return (
-
-
-
-
-
+
+
+
);
case NDKKind.Article:
return (
-
+
+
+
);
default:
return (
-
-
-
-
-
+
+
+
);
}
},
@@ -123,7 +79,7 @@ export function LocalUserWidget({ params }: { params: Widget }) {
return (
-
+
@@ -136,7 +92,7 @@ export function LocalUserWidget({ params }: { params: Widget }) {
- ) : items.length === 0 ? (
+ ) : data.length === 0 ? (
@@ -147,22 +103,10 @@ export function LocalUserWidget({ params }: { params: Widget }) {
) : (
-
-
- {items.map((item) => renderItem(item.index))}
-
-
+
+ {data.map((item) => renderItem(item))}
+
+
)}
diff --git a/src/utils/hooks/useNostr.ts b/src/utils/hooks/useNostr.ts
index 4afbdcad..98b54626 100644
--- a/src/utils/hooks/useNostr.ts
+++ b/src/utils/hooks/useNostr.ts
@@ -9,6 +9,7 @@ import {
import { message, open } from '@tauri-apps/api/dialog';
import { Body, fetch } from '@tauri-apps/api/http';
import { LRUCache } from 'lru-cache';
+import { NostrEventExt } from 'nostr-fetch';
import { nip19 } from 'nostr-tools';
import { useMemo } from 'react';
@@ -220,15 +221,19 @@ export function useNostr() {
};
const fetchNIP04Messages = async (sender: string) => {
- const senderMessages = await fetcher.fetchAllEvents(
- relayUrls,
- {
- kinds: [NDKKind.EncryptedDirectMessage],
- authors: [sender],
- '#p': [db.account.pubkey],
- },
- { since: 0 }
- );
+ let senderMessages: NostrEventExt
[] = [];
+
+ if (sender !== db.account.pubkey) {
+ senderMessages = await fetcher.fetchAllEvents(
+ relayUrls,
+ {
+ kinds: [NDKKind.EncryptedDirectMessage],
+ authors: [sender],
+ '#p': [db.account.pubkey],
+ },
+ { since: 0 }
+ );
+ }
const userMessages = await fetcher.fetchAllEvents(
relayUrls,