From e43a999ca8ecd282272753d6610bc0ddde3d0c0c Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Fri, 17 Mar 2023 09:08:48 +0700 Subject: [PATCH] added reply count --- src/components/note/content/index.tsx | 2 + src/components/note/reaction/index.tsx | 3 +- src/components/note/reply/index.tsx | 55 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/components/note/reply/index.tsx diff --git a/src/components/note/content/index.tsx b/src/components/note/content/index.tsx index 98a8e690..998c306e 100644 --- a/src/components/note/content/index.tsx +++ b/src/components/note/content/index.tsx @@ -1,6 +1,7 @@ import { ImageCard } from '@components/note/content/preview/imageCard'; import { Video } from '@components/note/content/preview/video'; import { Reaction } from '@components/note/reaction'; +import { Reply } from '@components/note/reply'; import { UserExtend } from '@components/user/extend'; import dynamic from 'next/dynamic'; @@ -87,6 +88,7 @@ export const Content = memo(function Content({ data }: { data: any }) { <>{previewAttachment()}
+
diff --git a/src/components/note/reaction/index.tsx b/src/components/note/reaction/index.tsx index 04f70f30..75061089 100644 --- a/src/components/note/reaction/index.tsx +++ b/src/components/note/reaction/index.tsx @@ -4,8 +4,7 @@ import { dateToUnix } from '@utils/getDate'; import { useLocalStorage } from '@rehooks/local-storage'; import { getEventHash, signEvent } from 'nostr-tools'; -import { memo, useContext, useState } from 'react'; -import { useEffect } from 'react'; +import { memo, useContext, useEffect, useState } from 'react'; export const Reaction = memo(function Reaction({ eventID, eventPubkey }: { eventID: string; eventPubkey: string }) { const relayPool: any = useContext(RelayContext); diff --git a/src/components/note/reply/index.tsx b/src/components/note/reply/index.tsx new file mode 100644 index 00000000..b757e5ac --- /dev/null +++ b/src/components/note/reply/index.tsx @@ -0,0 +1,55 @@ +import { RelayContext } from '@components/contexts/relay'; + +import { useLocalStorage } from '@rehooks/local-storage'; +import { memo, useContext, useEffect, useState } from 'react'; + +export const Reply = memo(function Reply({ eventID }: { eventID: string }) { + const relayPool: any = useContext(RelayContext); + + const [relays]: any = useLocalStorage('relays'); + const [reply, setReply] = useState(0); + + useEffect(() => { + relayPool.subscribe( + [ + { + '#e': [eventID], + since: 0, + kinds: [1], + limit: 10, + }, + ], + relays, + () => { + setReply(reply + 1); + }, + undefined, + (events: any, relayURL: any) => { + console.log(events, relayURL); + } + ); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [eventID, relayPool, relays]); + + return ( +
+
+ + + +
+ {reply} +
+ ); +});