added event collector

This commit is contained in:
Ren Amamiya
2023-04-10 15:50:38 +07:00
parent 213d7514d2
commit fabc0e6cc2
9 changed files with 232 additions and 57 deletions

View File

@@ -1,10 +1,48 @@
import BaseLayout from '@layouts/base';
import WithSidebarLayout from '@layouts/withSidebar';
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal } from 'react';
import { RelayContext } from '@components/relaysProvider';
import {
JSXElementConstructor,
ReactElement,
ReactFragment,
ReactPortal,
useContext,
useEffect,
useState,
} from 'react';
export default function Page() {
return <></>;
const [pool, relays]: any = useContext(RelayContext);
const [list, setList] = useState([]);
useEffect(() => {
const unsubscribe = pool.subscribe(
[
{
kinds: [40],
since: 0,
},
],
relays,
(event: any) => {
setList((list) => [event, ...list]);
}
);
return () => {
unsubscribe;
};
}, [pool, relays]);
return (
<div className="h-full w-full overflow-y-auto">
{list.map((channel) => (
<div key={channel.id}>{channel.content}</div>
))}
</div>
);
}
Page.getLayout = function getLayout(