-
@@ -155,4 +125,4 @@ export const NoteComment = ({
>
);
-};
+}
diff --git a/src/app/newsfeed/components/metadata/repost.tsx b/src/app/newsfeed/components/metadata/repost.tsx
new file mode 100644
index 00000000..69c17e78
--- /dev/null
+++ b/src/app/newsfeed/components/metadata/repost.tsx
@@ -0,0 +1,51 @@
+import RepostIcon from '@lume/shared/icons/repost';
+import { RelayContext } from '@lume/shared/relayProvider';
+import { WRITEONLY_RELAYS } from '@lume/stores/constants';
+import { dateToUnix } from '@lume/utils/getDate';
+import { useActiveAccount } from '@lume/utils/hooks/useActiveAccount';
+
+import { getEventHash, signEvent } from 'nostr-tools';
+import { useContext, useEffect, useState } from 'react';
+
+export default function NoteRepost({ id, pubkey, reposts }: { id: string; pubkey: string; reposts: number }) {
+ const pool: any = useContext(RelayContext);
+ const { account, isLoading, isError } = useActiveAccount();
+
+ const [count, setCount] = useState(0);
+
+ const submitEvent = (e: any) => {
+ e.stopPropagation();
+
+ if (!isLoading && !isError && account) {
+ const event: any = {
+ content: '',
+ kind: 6,
+ tags: [
+ ['e', id],
+ ['p', pubkey],
+ ],
+ created_at: dateToUnix(),
+ pubkey: account.pubkey,
+ };
+ event.id = getEventHash(event);
+ event.sig = signEvent(event, account.privkey);
+ // publish event to all relays
+ pool.publish(event, WRITEONLY_RELAYS);
+ // update state
+ setCount(count + 1);
+ } else {
+ console.log('error');
+ }
+ };
+
+ useEffect(() => {
+ setCount(reposts);
+ }, [reposts]);
+
+ return (
+
+ );
+}
diff --git a/src/app/newsfeed/components/note/base.tsx b/src/app/newsfeed/components/note/base.tsx
index 186a46d2..7cbc902b 100644
--- a/src/app/newsfeed/components/note/base.tsx
+++ b/src/app/newsfeed/components/note/base.tsx
@@ -1,4 +1,5 @@
import { contentParser } from '@lume/app/newsfeed/components/contentParser';
+import NoteMetadata from '@lume/app/newsfeed/components/note/metadata';
import { NoteParent } from '@lume/app/newsfeed/components/note/parent';
import { NoteDefaultUser } from '@lume/app/newsfeed/components/user/default';
@@ -44,7 +45,9 @@ export const NoteBase = memo(function NoteBase({ event }: { event: any }) {
-
e.stopPropagation()} className="mt-5 pl-[52px]">
+
e.stopPropagation()} className="mt-5 pl-[52px]">
+
+
);
diff --git a/src/app/newsfeed/components/note/meta/reaction.tsx b/src/app/newsfeed/components/note/meta/reaction.tsx
deleted file mode 100644
index 04cbe06f..00000000
--- a/src/app/newsfeed/components/note/meta/reaction.tsx
+++ /dev/null
@@ -1,69 +0,0 @@
-import { AccountContext } from '@lume/shared/accountProvider';
-import { RelayContext } from '@lume/shared/relaysProvider';
-import { WRITEONLY_RELAYS } from '@lume/stores/constants';
-import { dateToUnix } from '@lume/utils/getDate';
-
-import { Heart } from 'iconoir-react';
-import { getEventHash, signEvent } from 'nostr-tools';
-import { useContext, useEffect, useState } from 'react';
-
-export const NoteReaction = ({
- count,
- liked,
- eventID,
- eventPubkey,
-}: {
- count: number;
- liked: boolean;
- eventID: string;
- eventPubkey: string;
-}) => {
- const pool: any = useContext(RelayContext);
- const activeAccount: any = useContext(AccountContext);
-
- const [isReact, setIsReact] = useState(false);
- const [like, setLike] = useState(0);
-
- const handleLike = (e: any) => {
- e.stopPropagation();
-
- if (liked === false || isReact === false) {
- const event: any = {
- content: '+',
- kind: 7,
- tags: [
- ['e', eventID],
- ['p', eventPubkey],
- ],
- created_at: dateToUnix(),
- pubkey: activeAccount.pubkey,
- };
- event.id = getEventHash(event);
- event.sig = signEvent(event, activeAccount.privkey);
- // publish event to all relays
- pool.publish(event, WRITEONLY_RELAYS);
- // update state to change icon to filled heart
- setIsReact(true);
- // update counter
- setLike((like) => (like += 1));
- }
- };
-
- useEffect(() => {
- setIsReact(liked);
- setLike(count);
- }, [count, liked]);
-
- return (
-
- );
-};
diff --git a/src/app/newsfeed/components/note/metadata.tsx b/src/app/newsfeed/components/note/metadata.tsx
index 91543752..ba4b19b8 100644
--- a/src/app/newsfeed/components/note/metadata.tsx
+++ b/src/app/newsfeed/components/note/metadata.tsx
@@ -1,5 +1,65 @@
-import { memo } from 'react';
+import NoteReply from '@lume/app/newsfeed/components/metadata/reply';
+import ZapIcon from '@lume/shared/icons/zap';
+import { RelayContext } from '@lume/shared/relayProvider';
+import { READONLY_RELAYS } from '@lume/stores/constants';
-export const NoteMetadata = memo(function NoteMetadata() {
- return
;
-});
+import { useContext, useState } from 'react';
+import useSWRSubscription from 'swr/subscription';
+
+import NoteLike from '../metadata/like';
+import NoteRepost from '../metadata/repost';
+
+export default function NoteMetadata({ id, eventPubkey }: { id: string; eventPubkey: string }) {
+ const pool: any = useContext(RelayContext);
+
+ const [replies, setReplies] = useState(0);
+ const [likes, setLikes] = useState(0);
+ const [reposts, setReposts] = useState(0);
+
+ useSWRSubscription(id ? ['metadata', id] : null, ([, key], {}) => {
+ const unsubscribe = pool.subscribe(
+ [
+ {
+ '#e': [key],
+ since: 0,
+ kinds: [1, 6, 7],
+ limit: 20,
+ },
+ ],
+ READONLY_RELAYS,
+ (event: any) => {
+ switch (event.kind) {
+ case 1:
+ setReplies(replies + 1);
+ break;
+ case 6:
+ setReposts(reposts + 1);
+ break;
+ case 7:
+ if (event.content === '🤙' || event.content === '+') {
+ setLikes(likes + 1);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ );
+
+ return () => {
+ unsubscribe();
+ };
+ });
+
+ return (
+
+
+
+
+
+
+ );
+}
diff --git a/src/app/newsfeed/components/note/parent.tsx b/src/app/newsfeed/components/note/parent.tsx
index 6e145466..426918cb 100644
--- a/src/app/newsfeed/components/note/parent.tsx
+++ b/src/app/newsfeed/components/note/parent.tsx
@@ -1,4 +1,5 @@
import { contentParser } from '@lume/app/newsfeed/components/contentParser';
+import NoteMetadata from '@lume/app/newsfeed/components/note/metadata';
import { NoteDefaultUser } from '@lume/app/newsfeed/components/user/default';
import { RelayContext } from '@lume/shared/relayProvider';
import { READONLY_RELAYS } from '@lume/stores/constants';
@@ -36,7 +37,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
{error &&
failed to load
}
{!data ? (
-
+
@@ -67,7 +68,9 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
{contentParser(data.content, data.tags)}
-
e.stopPropagation()} className="mt-5 pl-[52px]">
+
e.stopPropagation()} className="mt-5 pl-[52px]">
+
+
>
)}
diff --git a/src/app/newsfeed/components/note/rootNote.tsx b/src/app/newsfeed/components/note/rootNote.tsx
index 117658b8..44a8c9a5 100644
--- a/src/app/newsfeed/components/note/rootNote.tsx
+++ b/src/app/newsfeed/components/note/rootNote.tsx
@@ -1,4 +1,5 @@
import { contentParser } from '@lume/app/newsfeed/components/contentParser';
+import NoteMetadata from '@lume/app/newsfeed/components/note/metadata';
import { NoteDefaultUser } from '@lume/app/newsfeed/components/user/default';
import { RelayContext } from '@lume/shared/relayProvider';
import { READONLY_RELAYS } from '@lume/stores/constants';
@@ -9,7 +10,7 @@ import { navigate } from 'vite-plugin-ssr/client/router';
export const RootNote = memo(function RootNote({ id, fallback }: { id: string; fallback?: any }) {
const pool: any = useContext(RelayContext);
- const parseFallback = fallback.length > 0 ? JSON.parse(fallback) : null;
+ const parseFallback = fallback.length > 1 ? JSON.parse(fallback) : null;
const { data, error } = useSWRSubscription(parseFallback ? null : id, (key, { next }) => {
const unsubscribe = pool.subscribe(
@@ -90,7 +91,9 @@ export const RootNote = memo(function RootNote({ id, fallback }: { id: string; f
{contentParser(data.content, data.tags)}
-
e.stopPropagation()} className="mt-5 pl-[52px]">
+
e.stopPropagation()} className="mt-5 pl-[52px]">
+
+
)}
>
diff --git a/src/shared/icons/like.tsx b/src/shared/icons/like.tsx
new file mode 100644
index 00000000..3c630475
--- /dev/null
+++ b/src/shared/icons/like.tsx
@@ -0,0 +1,14 @@
+import { SVGProps } from 'react';
+
+export default function LikeIcon(props: JSX.IntrinsicAttributes & SVGProps