added comment sql

This commit is contained in:
Ren Amamiya
2023-03-26 08:53:50 +07:00
parent 5d89a66ee0
commit 28215dbd5f
5 changed files with 37 additions and 24 deletions

View File

@@ -7,7 +7,7 @@ import { RelayContext } from '@components/relaysProvider';
import { relaysAtom } from '@stores/relays';
import { getNoteByID } from '@utils/storage';
import { getAllCommentNotes, getNoteByID } from '@utils/storage';
import { useAtomValue } from 'jotai';
import { useRouter } from 'next/router';
@@ -33,31 +33,12 @@ export default function Page() {
const [comments, setComments] = useState([]);
useEffect(() => {
let unsubscribe: () => void;
getNoteByID(id)
.then((res) => {
// update state
setRootEvent(res);
// get all comments
unsubscribe = pool.subscribe(
[
{
'#e': [id],
kinds: [1],
},
],
relays,
(event: any) => {
setComments((comments) => [...comments, event]);
}
);
getAllCommentNotes(id).then((res: any) => setComments(res));
})
.catch(console.error);
return () => {
unsubscribe();
};
}, [id, pool, relays]);
return (