From 57c17ffbf98e73d49c4069dbd2cb436b4d08e129 Mon Sep 17 00:00:00 2001
From: Ren Amamiya <123083837+reyamir@users.noreply.github.com>
Date: Mon, 4 Sep 2023 18:09:41 +0700
Subject: [PATCH] use nostr.com to display unfound event
---
src/shared/notes/child.tsx | 24 +++-
src/shared/notes/kinds/repost.tsx | 37 +++--
src/shared/notes/mentions/note.tsx | 31 ++++-
src/shared/widgets/local/follows.tsx | 198 +++++++++++++++++++++++++++
src/stores/constants.ts | 1 +
src/stores/widgets.ts | 5 +
6 files changed, 279 insertions(+), 17 deletions(-)
create mode 100644 src/shared/widgets/local/follows.tsx
diff --git a/src/shared/notes/child.tsx b/src/shared/notes/child.tsx
index 88a7b55c..1160f5a9 100644
--- a/src/shared/notes/child.tsx
+++ b/src/shared/notes/child.tsx
@@ -1,8 +1,11 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
+import { nip19 } from 'nostr-tools';
+import { Link } from 'react-router-dom';
import {
ArticleNote,
FileNote,
+ LinkPreview,
NoteActions,
NoteSkeleton,
TextNote,
@@ -40,21 +43,32 @@ export function ChildNote({ id, root }: { id: string; root?: string }) {
}
if (status === 'error') {
+ const noteLink = `https://nostr.com/${nip19.noteEncode(id)}`;
return (
<>
-
+
+

+
- Lume (System)
+ Lume (System)
-
-
Event not found, click to open this note via nostr.com
-
{id}
+
+
+
+ Lume cannot find this post with your current relays, but you can view it
+ via nostr.com.{' '}
+
+ Learn more
+
+
+
+
diff --git a/src/shared/notes/kinds/repost.tsx b/src/shared/notes/kinds/repost.tsx
index 159c6759..bdcdada2 100644
--- a/src/shared/notes/kinds/repost.tsx
+++ b/src/shared/notes/kinds/repost.tsx
@@ -1,9 +1,12 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
+import { nip19 } from 'nostr-tools';
import { useCallback } from 'react';
+import { Link } from 'react-router-dom';
import {
ArticleNote,
FileNote,
+ LinkPreview,
NoteActions,
NoteSkeleton,
RepostUser,
@@ -14,7 +17,8 @@ import { User } from '@shared/user';
import { useEvent } from '@utils/hooks/useEvent';
-export function Repost({ event }: { event: NDKEvent & { root_id: string } }) {
+export function Repost({ event }: { event: NDKEvent }) {
+ // @ts-expect-error, root_id isn't exist on NDKEvent
const { status, data } = useEvent(event.root_id, event.content);
const renderKind = useCallback(
@@ -44,14 +48,31 @@ export function Repost({ event }: { event: NDKEvent & { root_id: string } }) {
}
if (status === 'error') {
+ // @ts-expect-error, root_id isn't exist on NDKEvent
+ const noteLink = `https://nostr.com/${nip19.noteEncode(event.root_id)}`;
return (
-
-
-
- Failed to get post with ID
-
-
-
{event.id}
+
+
+
+

+
+
+ Lume (System)
+
+
+
+
+
+
+
+ Lume cannot find this post with your current relays, but you can view it
+ via nostr.com.{' '}
+
+ Learn more
+
+
+
+
diff --git a/src/shared/notes/mentions/note.tsx b/src/shared/notes/mentions/note.tsx
index 4be2bf74..b6a9eb95 100644
--- a/src/shared/notes/mentions/note.tsx
+++ b/src/shared/notes/mentions/note.tsx
@@ -1,11 +1,14 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
+import { nip19 } from 'nostr-tools';
import { memo } from 'react';
+import { Link } from 'react-router-dom';
import { useStorage } from '@libs/storage/provider';
import {
ArticleNote,
FileNote,
+ LinkPreview,
NoteSkeleton,
TextNote,
UnknownNote,
@@ -53,11 +56,31 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) {
}
if (status === 'error') {
+ const noteLink = `https://nostr.com/${nip19.noteEncode(id)}`;
return (
-
-
Event not found
-
- {id}
+
+
+
+

+
+
+ Lume (System)
+
+
+
+
+
+
+
+ Lume cannot find this post with your current relays, but you can view it
+ via nostr.com.{' '}
+
+ Learn more
+
+
+
+
+
);
diff --git a/src/shared/widgets/local/follows.tsx b/src/shared/widgets/local/follows.tsx
new file mode 100644
index 00000000..8769ad46
--- /dev/null
+++ b/src/shared/widgets/local/follows.tsx
@@ -0,0 +1,198 @@
+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 { useStorage } from '@libs/storage/provider';
+
+import { ArrowRightCircleIcon, LoaderIcon } from '@shared/icons';
+import {
+ ArticleNote,
+ FileNote,
+ NoteWrapper,
+ Repost,
+ TextNote,
+ UnknownNote,
+} from '@shared/notes';
+import { NoteSkeleton } from '@shared/notes/skeleton';
+import { TitleBar } from '@shared/titleBar';
+
+import { DBEvent } from '@utils/types';
+
+export function LocalFollowsWidget() {
+ const { db } = useStorage();
+ const { status, data, hasNextPage, isFetchingNextPage, fetchNextPage } =
+ useInfiniteQuery({
+ queryKey: ['local-follows-widget'],
+ queryFn: async ({ pageParam = 0 }) => {
+ return await db.getAllEventsByAuthors(db.account.follows, 20, pageParam);
+ },
+ getNextPageParam: (lastPage) => lastPage.nextCursor,
+ });
+
+ const dbEvents = useMemo(
+ () => (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;
+
+ const event: NDKEvent = JSON.parse(dbEvent.event as string);
+ switch (event.kind) {
+ case NDKKind.Text:
+ return (
+
+
+
+
+
+ );
+ case NDKKind.Repost:
+ return (
+
+
+
+ );
+ case 1063:
+ return (
+
+
+
+
+
+ );
+ case NDKKind.Article:
+ return (
+
+ );
+ default:
+ return (
+
+
+
+
+
+ );
+ }
+ },
+ [dbEvents]
+ );
+
+ return (
+
+
+
+ {status === 'loading' ? (
+
+ ) : dbEvents.length === 0 ? (
+
+
+

+
+
+ Your newsfeed is empty
+
+
+ Connect more people to explore more content
+
+
+
+
+ ) : (
+
+
+ {items.map((item) => renderItem(item.index))}
+
+
+ )}
+ {isFetchingNextPage && (
+
+ )}
+
+ {dbEvents.length > 0 ? (
+
+ ) : null}
+
+
+
+ );
+}
diff --git a/src/stores/constants.ts b/src/stores/constants.ts
index d36ea84c..6508d0ea 100644
--- a/src/stores/constants.ts
+++ b/src/stores/constants.ts
@@ -1,5 +1,6 @@
export const FULL_RELAYS = [
'wss://relay.damus.io',
+ 'wss://nos.lol',
'wss://relay.nostr.band/all',
'wss://nostr.mutinywallet.com',
];
diff --git a/src/stores/widgets.ts b/src/stores/widgets.ts
index 214e245c..6fbad8f0 100644
--- a/src/stores/widgets.ts
+++ b/src/stores/widgets.ts
@@ -20,6 +20,7 @@ export const WidgetKinds = {
articles: 103,
user: 104,
thread: 105,
+ follows: 106,
},
global: {
feeds: 1000,
@@ -54,6 +55,10 @@ export const DefaultWidgets = [
kind: WidgetKinds.local.articles,
title: 'Articles',
},
+ {
+ kind: WidgetKinds.local.follows,
+ title: 'Follows',
+ },
],
},
{