From 6abff45678fbca48e02e88597191b7d10cf5938a Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Tue, 27 Jun 2023 11:42:12 +0700 Subject: [PATCH] update thread --- src/app/auth/onboarding.tsx | 6 +- src/app/chat/components/item.tsx | 90 +++++++++---------- src/app/chat/components/list.tsx | 38 ++++---- src/app/chat/components/self.tsx | 74 +++++++-------- src/app/root.tsx | 14 ++- src/app/space/components/blocks/feed.tsx | 34 +++---- src/app/space/components/blocks/following.tsx | 74 +++++++-------- src/app/space/components/blocks/thread.tsx | 27 +++--- src/app/space/hooks/useLiveThread.tsx | 46 ++++++++++ src/app/space/hooks/useNewsfeed.tsx | 48 ++++++++++ src/app/trending/components/profile.tsx | 21 +++-- src/app/trending/components/trendingNotes.tsx | 13 ++- .../trending/components/trendingProfiles.tsx | 13 ++- src/libs/ndk.tsx | 35 ++++++-- src/main.tsx | 2 +- src/shared/accounts/active.tsx | 16 ++-- src/shared/multiAccounts.tsx | 15 ++-- src/shared/notes/mentions/note.tsx | 4 +- src/shared/notes/metadata.tsx | 87 +++++++++--------- src/shared/notes/parent.tsx | 4 +- src/shared/notes/replies/form.tsx | 6 +- src/shared/notes/replies/item.tsx | 2 +- src/shared/notes/replies/list.tsx | 5 +- src/shared/notes/repost.tsx | 4 +- src/stores/note.tsx | 13 +++ 25 files changed, 396 insertions(+), 295 deletions(-) create mode 100644 src/app/space/hooks/useLiveThread.tsx create mode 100644 src/app/space/hooks/useNewsfeed.tsx create mode 100644 src/stores/note.tsx diff --git a/src/app/auth/onboarding.tsx b/src/app/auth/onboarding.tsx index 1fe6f73f..f1324ac6 100644 --- a/src/app/auth/onboarding.tsx +++ b/src/app/auth/onboarding.tsx @@ -77,7 +77,11 @@ export function OnboardingScreen() { className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg px-6 font-medium text-zinc-100 bg-fuchsia-500 hover:bg-fuchsia-600" > {loading ? ( - + <> + + + + ) : ( <> diff --git a/src/app/chat/components/item.tsx b/src/app/chat/components/item.tsx index 036bbd9a..5cfc9814 100644 --- a/src/app/chat/components/item.tsx +++ b/src/app/chat/components/item.tsx @@ -6,54 +6,52 @@ import { NavLink } from "react-router-dom"; import { twMerge } from "tailwind-merge"; export function ChatsListItem({ data }: { data: any }) { - const { status, user, isFetching } = useProfile(data.sender_pubkey); + const { status, user } = useProfile(data.sender_pubkey); + + if (status === "loading") { + return ( +
+
+
+
+
+
+ ); + } return ( - <> - {status === "loading" && isFetching ? ( -
-
-
-
-
+ + twMerge( + "inline-flex h-9 items-center gap-2.5 rounded-md px-2.5", + isActive ? "bg-zinc-900/50 text-zinc-100" : "", + ) + } + > +
+ {data.sender_pubkey} +
+
+
+
+ {user?.nip05 || user?.displayName || shortenKey(data.sender_pubkey)} +
- ) : ( - - twMerge( - "inline-flex h-9 items-center gap-2.5 rounded-md px-2.5", - isActive ? "bg-zinc-900/50 text-zinc-100" : "", - ) - } - > -
- {data.sender_pubkey} -
-
-
-
- {user?.nip05 || - user?.displayName || - shortenKey(data.sender_pubkey)} -
-
-
- {data.new_messages > 0 && ( - - {data.new_messages} - - )} -
-
-
- )} - +
+ {data.new_messages > 0 && ( + + {data.new_messages} + + )} +
+
+
); } diff --git a/src/app/chat/components/list.tsx b/src/app/chat/components/list.tsx index 262ef705..536df6d8 100644 --- a/src/app/chat/components/list.tsx +++ b/src/app/chat/components/list.tsx @@ -26,6 +26,21 @@ export function ChatsList() { }, ); + if (status === "loading") { + return ( +
+
+
+
+
+
+
+
+
+
+ ); + } + return (
@@ -37,24 +52,11 @@ export function ChatsList() {
)} - {status === "loading" ? ( - <> -
-
-
-
-
-
-
-
- - ) : ( - chats.map((item) => { - if (account.pubkey !== item.sender_pubkey) { - return ; - } - }) - )} + {chats.map((item) => { + if (account.pubkey !== item.sender_pubkey) { + return ; + } + })} {isFetching && (
diff --git a/src/app/chat/components/self.tsx b/src/app/chat/components/self.tsx index 480855c5..fa3ad60a 100644 --- a/src/app/chat/components/self.tsx +++ b/src/app/chat/components/self.tsx @@ -6,44 +6,44 @@ import { NavLink } from "react-router-dom"; import { twMerge } from "tailwind-merge"; export function ChatsListSelfItem({ data }: { data: any }) { - const { status, user, isFetching } = useProfile(data.pubkey); + const { status, user } = useProfile(data.pubkey); + + if (status === "loading") { + return ( +
+
+
+
+
+
+ ); + } return ( - <> - {status === "loading" && isFetching ? ( -
-
-
-
-
-
- ) : ( - - twMerge( - "inline-flex h-9 items-center gap-2.5 rounded-md px-2.5", - isActive ? "bg-zinc-900/50 text-zinc-100" : "", - ) - } - > -
- {data.pubkey} -
-
-
- {user?.nip05 || user?.name || shortenKey(data.pubkey)} -
- (you) -
-
- )} - + + twMerge( + "inline-flex h-9 items-center gap-2.5 rounded-md px-2.5", + isActive ? "bg-zinc-900/50 text-zinc-100" : "", + ) + } + > +
+ {data.pubkey} +
+
+
+ {user?.nip05 || user?.name || shortenKey(data.pubkey)} +
+ (you) +
+
); } diff --git a/src/app/root.tsx b/src/app/root.tsx index d6f32434..1cfa6b32 100644 --- a/src/app/root.tsx +++ b/src/app/root.tsx @@ -28,22 +28,18 @@ export function Root() { async function fetchNotes() { try { const follows = JSON.parse(account.follows); - let queryNoteSince: number; + let since: number; - if (totalNotes === 0) { - queryNoteSince = dateToUnix(getHourAgo(48, now.current)); + if (totalNotes === 0 || lastLogin === 0) { + since = dateToUnix(getHourAgo(48, now.current)); } else { - if (lastLogin > 0) { - queryNoteSince = lastLogin; - } else { - queryNoteSince = dateToUnix(getHourAgo(48, now.current)); - } + since = lastLogin; } const filter: NDKFilter = { kinds: [1, 6], authors: follows, - since: queryNoteSince, + since: since, }; const events = await prefetchEvents(ndk, filter); diff --git a/src/app/space/components/blocks/feed.tsx b/src/app/space/components/blocks/feed.tsx index 17487e2d..0a623f76 100644 --- a/src/app/space/components/blocks/feed.tsx +++ b/src/app/space/components/blocks/feed.tsx @@ -15,25 +15,19 @@ const TIME = Math.floor(Date.now() / 1000); export function FeedBlock({ params }: { params: any }) { const queryClient = useQueryClient(); - const { - status, - data, - fetchNextPage, - hasNextPage, - isFetching, - isFetchingNextPage, - }: any = useInfiniteQuery({ - queryKey: ["newsfeed", params.content], - queryFn: async ({ pageParam = 0 }) => { - return await getNotesByAuthors( - params.content, - TIME, - ITEM_PER_PAGE, - pageParam, - ); - }, - getNextPageParam: (lastPage) => lastPage.nextCursor, - }); + const { status, data, fetchNextPage, hasNextPage, isFetchingNextPage }: any = + useInfiniteQuery({ + queryKey: ["newsfeed", params.content], + queryFn: async ({ pageParam = 0 }) => { + return await getNotesByAuthors( + params.content, + TIME, + ITEM_PER_PAGE, + pageParam, + ); + }, + getNextPageParam: (lastPage) => lastPage.nextCursor, + }); const notes = data ? data.pages.flatMap((d: { data: any }) => d.data) : []; const parentRef = useRef(); @@ -119,7 +113,7 @@ export function FeedBlock({ params }: { params: any }) {
)} - {isFetching && !isFetchingNextPage && ( + {isFetchingNextPage && (
diff --git a/src/app/space/components/blocks/following.tsx b/src/app/space/components/blocks/following.tsx index 98305147..545e8b3f 100644 --- a/src/app/space/components/blocks/following.tsx +++ b/src/app/space/components/blocks/following.tsx @@ -1,30 +1,31 @@ -import { createNote, getNotes } from "@libs/storage"; -import { NDKEvent, NDKFilter, NDKSubscription } from "@nostr-dev-kit/ndk"; +import { useNewsfeed } from "@app/space/hooks/useNewsfeed"; +import { getNotes } from "@libs/storage"; import { Note } from "@shared/notes/note"; import { NoteSkeleton } from "@shared/notes/skeleton"; -import { RelayContext } from "@shared/relayProvider"; import { TitleBar } from "@shared/titleBar"; +import { useNote } from "@stores/note"; import { useInfiniteQuery } from "@tanstack/react-query"; import { useVirtualizer } from "@tanstack/react-virtual"; -import { dateToUnix } from "@utils/date"; -import { useAccount } from "@utils/hooks/useAccount"; -import { useContext, useEffect, useRef } from "react"; +import { useEffect, useRef } from "react"; const ITEM_PER_PAGE = 10; const TIME = Math.floor(Date.now() / 1000); export function FollowingBlock({ block }: { block: number }) { - const ndk = useContext(RelayContext); - - const { account } = useAccount(); + // subscribe for live update + useNewsfeed(); + const [hasNewNote, toggleHasNewNote] = useNote((state) => [ + state.hasNewNote, + state.toggleHasNewNote, + ]); const { status, data, fetchNextPage, hasNextPage, - isFetching, isFetchingNextPage, + refetch, }: any = useInfiniteQuery({ queryKey: ["newsfeed-circle"], queryFn: async ({ pageParam = 0 }) => { @@ -61,39 +62,17 @@ export function FollowingBlock({ block }: { block: number }) { } }, [notes.length, fetchNextPage, rowVirtualizer.getVirtualItems()]); - useEffect(() => { - const follows = account ? JSON.parse(account.follows) : []; - - const filter: NDKFilter = { - kinds: [1, 6], - authors: follows, - since: dateToUnix(), - }; - - const sub = account ? ndk.subscribe(filter) : null; - if (sub) { - sub.addListener("event", (event: NDKEvent) => { - createNote( - event.id, - event.pubkey, - event.kind, - event.tags, - event.content, - event.created_at, - ); - }); - } - - return () => { - if (sub) { - sub.stop(); - } - }; - }, [account]); + const refreshFirstPage = () => { + // refetch + refetch({ refetchPage: (page, index) => index === 0 }); + // scroll to top + rowVirtualizer.scrollToIndex(1); + // stop notify + toggleHasNewNote(false); + }; const renderItem = (index: string | number) => { const note = notes[index]; - if (!note) return; return (
@@ -103,8 +82,19 @@ export function FollowingBlock({ block }: { block: number }) { }; return ( -
+
+ {hasNewNote && ( +
+ +
+ )}
)} - {isFetching && !isFetchingNextPage && ( + {isFetchingNextPage && (
diff --git a/src/app/space/components/blocks/thread.tsx b/src/app/space/components/blocks/thread.tsx index e0420425..74f485f8 100644 --- a/src/app/space/components/blocks/thread.tsx +++ b/src/app/space/components/blocks/thread.tsx @@ -1,3 +1,4 @@ +import { useLiveThread } from "@app/space/hooks/useLiveThread"; import { getNoteByID, removeBlock } from "@libs/storage"; import { Kind1 } from "@shared/notes/contents/kind1"; import { Kind1063 } from "@shared/notes/contents/kind1063"; @@ -11,14 +12,15 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { parser } from "@utils/parser"; export function ThreadBlock({ params }: { params: any }) { + useLiveThread(params.content); + const queryClient = useQueryClient(); - const { status, data, isFetching } = useQuery( - ["thread", params.content], - async () => { - return await getNoteByID(params.content); - }, - ); + const { status, data } = useQuery(["thread", params.content], async () => { + const res = await getNoteByID(params.content); + res["content"] = parser(res); + return res; + }); const block = useMutation({ mutationFn: (id: string) => { @@ -29,13 +31,11 @@ export function ThreadBlock({ params }: { params: any }) { }, }); - const content = data ? parser(data) : null; - return (
block.mutate(params.id)} />
- {status === "loading" || isFetching ? ( + {status === "loading" ? (
@@ -46,13 +46,16 @@ export function ThreadBlock({ params }: { params: any }) {
- {data.kind === 1 && } + {data.kind === 1 && } {data.kind === 1063 && } - +
- +
)} diff --git a/src/app/space/hooks/useLiveThread.tsx b/src/app/space/hooks/useLiveThread.tsx new file mode 100644 index 00000000..9374cf1e --- /dev/null +++ b/src/app/space/hooks/useLiveThread.tsx @@ -0,0 +1,46 @@ +import { createReplyNote } from "@libs/storage"; +import { NDKEvent, NDKFilter } from "@nostr-dev-kit/ndk"; +import { RelayContext } from "@shared/relayProvider"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { useContext, useEffect, useRef } from "react"; + +export function useLiveThread(id: string) { + const ndk = useContext(RelayContext); + const queryClient = useQueryClient(); + const now = useRef(Math.floor(Date.now() / 1000)); + + const thread = useMutation({ + mutationFn: (data: NDKEvent) => { + return createReplyNote( + id, + data.id, + data.pubkey, + data.kind, + data.tags, + data.content, + data.created_at, + ); + }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["replies", id] }); + }, + }); + + useEffect(() => { + const filter: NDKFilter = { + kinds: [1], + "#e": [id], + since: now.current, + }; + + const sub = ndk.subscribe(filter, { closeOnEose: false }); + + sub.addListener("event", (event: NDKEvent) => { + thread.mutate(event); + }); + + return () => { + sub.stop(); + }; + }, []); +} diff --git a/src/app/space/hooks/useNewsfeed.tsx b/src/app/space/hooks/useNewsfeed.tsx new file mode 100644 index 00000000..2aa97bc6 --- /dev/null +++ b/src/app/space/hooks/useNewsfeed.tsx @@ -0,0 +1,48 @@ +import { createNote } from "@libs/storage"; +import { NDKEvent, NDKFilter } from "@nostr-dev-kit/ndk"; +import { RelayContext } from "@shared/relayProvider"; +import { useNote } from "@stores/note"; +import { useAccount } from "@utils/hooks/useAccount"; +import { useContext, useEffect, useRef } from "react"; + +export function useNewsfeed() { + const ndk = useContext(RelayContext); + const sub = useRef(null); + const now = useRef(Math.floor(Date.now() / 1000)); + const toggleHasNewNote = useNote((state) => state.toggleHasNewNote); + + const { status, account } = useAccount(); + + useEffect(() => { + if (status === "success" && account) { + const follows = account ? JSON.parse(account.follows) : []; + + const filter: NDKFilter = { + kinds: [1, 6], + authors: follows, + since: now.current, + }; + + sub.current = ndk.subscribe(filter, { closeOnEose: false }); + + sub.current.addListener("event", (event: NDKEvent) => { + console.log("new note: ", event); + // add to db + createNote( + event.id, + event.pubkey, + event.kind, + event.tags, + event.content, + event.created_at, + ); + // notify user about created note + toggleHasNewNote(true); + }); + } + + return () => { + sub.current.stop(); + }; + }, [status]); +} diff --git a/src/app/trending/components/profile.tsx b/src/app/trending/components/profile.tsx index ff10e608..ab79a429 100644 --- a/src/app/trending/components/profile.tsx +++ b/src/app/trending/components/profile.tsx @@ -5,16 +5,15 @@ import { compactNumber } from "@utils/number"; import { shortenKey } from "@utils/shortenKey"; export function Profile({ data }: { data: any }) { - const { - status, - data: userStats, - isFetching, - } = useQuery(["user-stats", data.pubkey], async () => { - const res = await fetch( - `https://api.nostr.band/v0/stats/profile/${data.pubkey}`, - ); - return res.json(); - }); + const { status, data: userStats } = useQuery( + ["user-stats", data.pubkey], + async () => { + const res = await fetch( + `https://api.nostr.band/v0/stats/profile/${data.pubkey}`, + ); + return res.json(); + }, + ); const embedProfile = data.profile ? JSON.parse(data.profile.content) : null; const profile = embedProfile; @@ -51,7 +50,7 @@ export function Profile({ data }: { data: any }) {

- {status === "loading" || isFetching ? ( + {status === "loading" ? (

Loading...

) : (
diff --git a/src/app/trending/components/trendingNotes.tsx b/src/app/trending/components/trendingNotes.tsx index af38479d..6613142a 100644 --- a/src/app/trending/components/trendingNotes.tsx +++ b/src/app/trending/components/trendingNotes.tsx @@ -4,19 +4,16 @@ import { TitleBar } from "@shared/titleBar"; import { useQuery } from "@tanstack/react-query"; export function TrendingNotes() { - const { status, data, isFetching } = useQuery( - ["trending-notes"], - async () => { - const res = await fetch("https://api.nostr.band/v0/trending/notes"); - return res.json(); - }, - ); + const { status, data } = useQuery(["trending-notes"], async () => { + const res = await fetch("https://api.nostr.band/v0/trending/notes"); + return res.json(); + }); return (
- {status === "loading" || isFetching ? ( + {status === "loading" ? (
diff --git a/src/app/trending/components/trendingProfiles.tsx b/src/app/trending/components/trendingProfiles.tsx index f7f12a4a..e6c23092 100644 --- a/src/app/trending/components/trendingProfiles.tsx +++ b/src/app/trending/components/trendingProfiles.tsx @@ -4,19 +4,16 @@ import { TitleBar } from "@shared/titleBar"; import { useQuery } from "@tanstack/react-query"; export function TrendingProfiles() { - const { status, data, isFetching } = useQuery( - ["trending-profiles"], - async () => { - const res = await fetch("https://api.nostr.band/v0/trending/profiles"); - return res.json(); - }, - ); + const { status, data } = useQuery(["trending-profiles"], async () => { + const res = await fetch("https://api.nostr.band/v0/trending/profiles"); + return res.json(); + }); return (
- {status === "loading" || isFetching ? ( + {status === "loading" ? (
diff --git a/src/libs/ndk.tsx b/src/libs/ndk.tsx index eca863f2..a18c40ab 100644 --- a/src/libs/ndk.tsx +++ b/src/libs/ndk.tsx @@ -1,3 +1,4 @@ +import { createReplyNote } from "./storage"; import NDK, { NDKConstructorParams, NDKEvent, @@ -10,12 +11,22 @@ import { FULL_RELAYS } from "@stores/constants"; import { useAccount } from "@utils/hooks/useAccount"; import { useContext } from "react"; -export async function initNDK( - relays?: string[], - cache?: boolean, -): Promise { +export async function initNDK(relays?: string[]): Promise { const opts: NDKConstructorParams = {}; - opts.explicitRelayUrls = relays || FULL_RELAYS; + const defaultRelays = new Set(relays || FULL_RELAYS); + + /* + for (const relay of defaultRelays) { + const url = new URL(relay); + url.protocol = url.protocol = url.protocol.replace("wss", "https"); + const res = await fetch(url.href, { method: "HEAD", timeout: 5 }); + if (!res.ok) { + defaultRelays.delete(relay); + } + } + */ + + opts.explicitRelayUrls = [...defaultRelays]; const ndk = new NDK(opts); await ndk.connect(); @@ -40,7 +51,7 @@ export async function prefetchEvents( }); relaySetSubscription.on("eose", () => { - setTimeout(() => resolve(new Set(events.values())), 5000); + setTimeout(() => resolve(new Set(events.values())), 3000); }); }); } @@ -54,11 +65,15 @@ export function usePublish() { ndk.signer = signer; } - function publish({ + const publish = ({ content, kind, tags, - }: { content: string; kind: NDKKind; tags: string[][] }) { + }: { + content: string; + kind: NDKKind; + tags: string[][]; + }): NDKEvent => { const event = new NDKEvent(ndk); event.content = content; @@ -68,7 +83,9 @@ export function usePublish() { event.tags = tags; event.publish(); - } + + return event; + }; return publish; } diff --git a/src/main.tsx b/src/main.tsx index 3cea0f18..c4849826 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -20,6 +20,6 @@ root.render( - + , ); diff --git a/src/shared/accounts/active.tsx b/src/shared/accounts/active.tsx index 71945b40..366caa3c 100644 --- a/src/shared/accounts/active.tsx +++ b/src/shared/accounts/active.tsx @@ -87,19 +87,21 @@ export function ActiveAccount({ data }: { data: any }) { }; }, []); + if (status === "loading") { + return
; + } + return ( - + +
+
); } diff --git a/src/shared/multiAccounts.tsx b/src/shared/multiAccounts.tsx index 6f0092ea..7b863ac3 100644 --- a/src/shared/multiAccounts.tsx +++ b/src/shared/multiAccounts.tsx @@ -7,13 +7,12 @@ import { useState } from "react"; import { Link } from "react-router-dom"; export function MultiAccounts() { - const { - status, - data: activeAccount, - isFetching, - } = useQuery(["activeAccount"], async () => { - return await getActiveAccount(); - }); + const { status, data: activeAccount } = useQuery( + ["activeAccount"], + async () => { + return await getActiveAccount(); + }, + ); const [open, setOpen] = useState(false); @@ -25,7 +24,7 @@ export function MultiAccounts() {
- {status === "loading" || isFetching ? ( + {status === "loading" ? (
) : ( diff --git a/src/shared/notes/mentions/note.tsx b/src/shared/notes/mentions/note.tsx index 2b12ad61..c41dfdc3 100644 --- a/src/shared/notes/mentions/note.tsx +++ b/src/shared/notes/mentions/note.tsx @@ -8,7 +8,7 @@ import { useEvent } from "@utils/hooks/useEvent"; import { memo } from "react"; export const MentionNote = memo(function MentionNote({ id }: { id: string }) { - const { status, data, isFetching } = useEvent(id); + const { status, data } = useEvent(id); const kind1 = data?.kind === 1 ? data.content : null; const kind1063 = data?.kind === 1063 ? data.tags : null; @@ -39,7 +39,7 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) { onKeyDown={(e) => openThread(e, id)} className="mt-3 rounded-lg bg-zinc-800 border-t border-zinc-700/50 px-3 py-3" > - {isFetching || status === "loading" ? ( + {status === "loading" ? ( ) : ( <> diff --git a/src/shared/notes/metadata.tsx b/src/shared/notes/metadata.tsx index 3ec6b708..6a7c73ba 100644 --- a/src/shared/notes/metadata.tsx +++ b/src/shared/notes/metadata.tsx @@ -19,60 +19,57 @@ export function NoteMetadata({ currentBlock?: number; }) { const ndk = useContext(RelayContext); - const { status, data, isFetching } = useQuery( - ["note-metadata", id], - async () => { - let replies = 0; - let reposts = 0; - let zap = 0; + const { status, data } = useQuery(["note-metadata", id], async () => { + let replies = 0; + let reposts = 0; + let zap = 0; - const filter: NDKFilter = { - "#e": [id], - kinds: [1, 6, 9735], - }; + const filter: NDKFilter = { + "#e": [id], + kinds: [1, 6, 9735], + }; - const events = await ndk.fetchEvents(filter); - events.forEach((event: NDKEvent) => { - switch (event.kind) { - case 1: - replies += 1; - createReplyNote( - id, - event.id, - event.pubkey, - event.kind, - event.tags, - event.content, - event.created_at, + const events = await ndk.fetchEvents(filter); + events.forEach((event: NDKEvent) => { + switch (event.kind) { + case 1: + replies += 1; + createReplyNote( + id, + event.id, + event.pubkey, + event.kind, + event.tags, + event.content, + event.created_at, + ); + break; + case 6: + reposts += 1; + break; + case 9735: { + const bolt11 = event.tags.find((tag) => tag[0] === "bolt11")[1]; + if (bolt11) { + const decoded = decode(bolt11); + const amount = decoded.sections.find( + (item) => item.name === "amount", ); - break; - case 6: - reposts += 1; - break; - case 9735: { - const bolt11 = event.tags.find((tag) => tag[0] === "bolt11")[1]; - if (bolt11) { - const decoded = decode(bolt11); - const amount = decoded.sections.find( - (item) => item.name === "amount", - ); - const sats = amount.value / 1000; - zap += sats; - } - break; + const sats = amount.value / 1000; + zap += sats; } - default: - break; + break; } - }); + default: + break; + } + }); - return { replies, reposts, zap }; - }, - ); + return { replies, reposts, zap }; + }); return (
- {status === "loading" || isFetching ? ( + {status === "loading" ? ( <>
- {isFetching || status === "loading" ? ( + {status === "loading" ? ( ) : ( <> diff --git a/src/shared/notes/replies/form.tsx b/src/shared/notes/replies/form.tsx index ae0d4e50..f2d5897c 100644 --- a/src/shared/notes/replies/form.tsx +++ b/src/shared/notes/replies/form.tsx @@ -14,7 +14,7 @@ export function NoteReplyForm({ id }: { id: string }) { const [value, setValue] = useState(""); - const submitEvent = () => { + const submit = () => { const tags = [["e", id]]; // publish event @@ -28,7 +28,7 @@ export function NoteReplyForm({ id }: { id: string }) {