openThread(e)}
- className="relative z-10 m-0 flex h-min min-h-min w-full select-text flex-col border-b border-zinc-800 px-3 py-5 hover:bg-black/20"
+ className="relative z-10 flex h-min min-h-min w-full select-text flex-col border-b border-zinc-800 px-3 py-5 hover:bg-black/20"
>
{parentNote()}
diff --git a/src/components/note/parent.tsx b/src/components/note/parent.tsx
index 311dfc48..cf163462 100644
--- a/src/components/note/parent.tsx
+++ b/src/components/note/parent.tsx
@@ -7,19 +7,18 @@ import { createNote, getNoteByID } from '@utils/storage';
import { getParentID } from '@utils/transform';
import useLocalStorage from '@rehooks/local-storage';
-import { memo, useCallback, useContext, useEffect, useRef, useState } from 'react';
+import { memo, useCallback, useContext, useEffect, useState } from 'react';
export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
const [pool, relays]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [event, setEvent] = useState(null);
- const unsubscribe = useRef(null);
const content = event ? contentParser(event.content, event.tags) : '';
const fetchEvent = useCallback(async () => {
- unsubscribe.current = pool.subscribe(
+ const unsubscribe = pool.subscribe(
[
{
ids: [id],
@@ -50,9 +49,13 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
unsubscribeOnEose: true,
}
);
+
+ return () => {
+ unsubscribe();
+ };
}, [activeAccount.id, id, pool, relays]);
- const checkNoteExist = useCallback(async () => {
+ const checkNoteIsSaved = useCallback(async () => {
getNoteByID(id)
.then((res) => {
if (res) {
@@ -65,14 +68,16 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
}, [fetchEvent, id]);
useEffect(() => {
- checkNoteExist();
+ let ignore = false;
+
+ if (!ignore) {
+ checkNoteIsSaved();
+ }
return () => {
- if (unsubscribe.current) {
- unsubscribe.current();
- }
+ ignore = true;
};
- }, [checkNoteExist]);
+ }, [checkNoteIsSaved]);
if (event) {
return (
diff --git a/src/components/note/quote.tsx b/src/components/note/quote.tsx
index 10a07514..671e236d 100644
--- a/src/components/note/quote.tsx
+++ b/src/components/note/quote.tsx
@@ -6,19 +6,18 @@ import { createNote, getNoteByID } from '@utils/storage';
import { getParentID } from '@utils/transform';
import useLocalStorage from '@rehooks/local-storage';
-import { memo, useCallback, useContext, useEffect, useRef, useState } from 'react';
+import { memo, useCallback, useContext, useEffect, useState } from 'react';
export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
const [pool, relays]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [event, setEvent] = useState(null);
- const unsubscribe = useRef(null);
const content = event ? contentParser(event.content, event.tags) : '';
const fetchEvent = useCallback(async () => {
- unsubscribe.current = pool.subscribe(
+ const unsubscribe = pool.subscribe(
[
{
ids: [id],
@@ -48,9 +47,13 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
unsubscribeOnEose: true,
}
);
+
+ return () => {
+ unsubscribe();
+ };
}, [activeAccount.id, id, pool, relays]);
- const checkNoteExist = useCallback(async () => {
+ const checkNoteIsSaved = useCallback(async () => {
getNoteByID(id)
.then((res) => {
if (res) {
@@ -63,14 +66,16 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
}, [fetchEvent, id]);
useEffect(() => {
- checkNoteExist();
+ let ignore = false;
+
+ if (!ignore) {
+ checkNoteIsSaved();
+ }
return () => {
- if (unsubscribe.current) {
- unsubscribe.current();
- }
+ ignore = true;
};
- }, [checkNoteExist]);
+ }, [checkNoteIsSaved]);
if (event) {
return (
diff --git a/src/components/note/quoteRepost.tsx b/src/components/note/quoteRepost.tsx
index 32ae36f9..e1d57c0d 100644
--- a/src/components/note/quoteRepost.tsx
+++ b/src/components/note/quoteRepost.tsx
@@ -21,7 +21,7 @@ export const NoteQuoteRepost = memo(function NoteQuoteRepost({ event }: { event:
};
return (
-
+
diff --git a/src/components/note/rootNote.tsx b/src/components/note/rootNote.tsx
index 3d760b89..f09d582d 100644
--- a/src/components/note/rootNote.tsx
+++ b/src/components/note/rootNote.tsx
@@ -5,7 +5,7 @@ import { UserExtend } from '@components/user/extend';
import { contentParser } from '@utils/parser';
import { useRouter } from 'next/navigation';
-import { memo, useCallback, useContext, useEffect, useRef, useState } from 'react';
+import { memo, useCallback, useContext, useEffect, useState } from 'react';
export const RootNote = memo(function RootNote({ event }: { event: any }) {
const router = useRouter();
@@ -14,17 +14,15 @@ export const RootNote = memo(function RootNote({ event }: { event: any }) {
const [data, setData] = useState(null);
const [content, setContent] = useState('');
- const unsubscribe = useRef(null);
-
const openUserPage = (e) => {
e.stopPropagation();
- router.push(`/nostr/users/${event.pubkey}`);
+ router.push(`/nostr/user?pubkey=${event.pubkey}`);
};
const openThread = (e) => {
const selection = window.getSelection();
if (selection.toString().length === 0) {
- router.push(`/nostr/newsfeed/${event.id}`);
+ router.push(`/nostr/newsfeed/note?id=${event.parent_id}`);
} else {
e.stopPropagation();
}
@@ -32,7 +30,7 @@ export const RootNote = memo(function RootNote({ event }: { event: any }) {
const fetchEvent = useCallback(
async (id: string) => {
- unsubscribe.current = pool.subscribe(
+ const unsubscribe = pool.subscribe(
[
{
ids: [id],
@@ -50,17 +48,29 @@ export const RootNote = memo(function RootNote({ event }: { event: any }) {
unsubscribeOnEose: true,
}
);
+
+ return () => {
+ unsubscribe();
+ };
},
[pool, relays]
);
useEffect(() => {
- if (typeof event === 'object') {
- setData(event);
- setContent(contentParser(event.content, event.tags));
- } else {
- fetchEvent(event);
+ let ignore = false;
+
+ if (!ignore) {
+ if (typeof event === 'object') {
+ setData(event);
+ setContent(contentParser(event.content, event.tags));
+ } else {
+ fetchEvent(event);
+ }
}
+
+ return () => {
+ ignore = true;
+ };
}, [event, fetchEvent]);
if (data) {