diff --git a/src/components/note/content/index.tsx b/src/components/note/content/index.tsx index 1ff240f5..3e1f700e 100644 --- a/src/components/note/content/index.tsx +++ b/src/components/note/content/index.tsx @@ -32,7 +32,7 @@ export const Content = memo(function Content({ data }: { data: any }) { return ; } else { // #TODO: handle mention other note - console.log(tags[match]); + // console.log(tags[match]); } }); } diff --git a/src/components/note/content/metadata.tsx b/src/components/note/content/metadata.tsx index a7d72763..3fbac9ba 100644 --- a/src/components/note/content/metadata.tsx +++ b/src/components/note/content/metadata.tsx @@ -3,7 +3,7 @@ import { CommentsCounter } from '@components/note/counter/comments'; import { LikesCounter } from '@components/note/counter/likes'; import { useLocalStorage } from '@rehooks/local-storage'; -import { useContext, useMemo, useState } from 'react'; +import { useContext, useEffect, useState } from 'react'; export default function NoteMetadata({ eventID, @@ -22,8 +22,8 @@ export default function NoteMetadata({ const [likes, setLikes] = useState(0); const [comments, setComments] = useState(0); - useMemo(() => { - relayPool.subscribe( + useEffect(() => { + const unsubscribe = relayPool.subscribe( [ { '#e': [eventID], @@ -52,6 +52,10 @@ export default function NoteMetadata({ unsubscribeOnEose: true, } ); + + return () => { + unsubscribe(); + }; }, [eventID, relayPool, relays]); return ( diff --git a/src/components/note/counter/likes.tsx b/src/components/note/counter/likes.tsx index 55084cad..9a59c3e5 100644 --- a/src/components/note/counter/likes.tsx +++ b/src/components/note/counter/likes.tsx @@ -7,7 +7,7 @@ import LikedIcon from '@assets/icons/liked'; import { useLocalStorage } from '@rehooks/local-storage'; import { getEventHash, signEvent } from 'nostr-tools'; -import { memo, useCallback, useContext, useState } from 'react'; +import { memo, useContext, useState } from 'react'; export const LikesCounter = memo(function LikesCounter({ count, @@ -26,31 +26,28 @@ export const LikesCounter = memo(function LikesCounter({ const [isReact, setIsReact] = useState(false); const [like, setLike] = useState(count); - const handleLike = useCallback( - (e: any) => { - e.stopPropagation(); + const handleLike = (e: any) => { + e.stopPropagation(); - const event: any = { - content: '+', - kind: 7, - tags: [ - ['e', eventID], - ['p', eventPubkey], - ], - created_at: dateToUnix(), - pubkey: currentUser.id, - }; - event.id = getEventHash(event); - event.sig = signEvent(event, currentUser.privkey); - // publish event to all relays - relayPool.publish(event, relays); - // update state to change icon to filled heart - setIsReact(true); - // update counter - setLike(like + 1); - }, - [eventID, eventPubkey, currentUser.id, currentUser.privkey, relayPool, relays, like] - ); + const event: any = { + content: '+', + kind: 7, + tags: [ + ['e', eventID], + ['p', eventPubkey], + ], + created_at: dateToUnix(), + pubkey: currentUser.id, + }; + event.id = getEventHash(event); + event.sig = signEvent(event, currentUser.privkey); + // publish event to all relays + relayPool.publish(event, relays); + // update state to change icon to filled heart + setIsReact(true); + // update counter + setLike(like + 1); + }; return (