added get channels

This commit is contained in:
Ren Amamiya
2023-04-10 16:44:18 +07:00
parent fabc0e6cc2
commit 0bfcb10253
5 changed files with 126 additions and 3 deletions

View File

@@ -0,0 +1,55 @@
import BaseLayout from '@layouts/base';
import WithSidebarLayout from '@layouts/withSidebar';
import { RelayContext } from '@components/relaysProvider';
import { useRouter } from 'next/router';
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal, useContext, useEffect } from 'react';
export default function Page() {
const [pool, relays]: any = useContext(RelayContext);
const router = useRouter();
const id: string | string[] = router.query.id || null;
useEffect(() => {
const unsubscribe = pool.subscribe(
[
{
kinds: [42],
since: 0,
},
],
relays,
(event: any) => {
console.log(event);
}
);
return () => {
unsubscribe;
};
}, [pool, relays]);
return (
<div className="flex h-full w-full flex-col justify-between">
<p>{id}</p>
</div>
);
}
Page.getLayout = function getLayout(
page:
| string
| number
| boolean
| ReactElement<unknown, string | JSXElementConstructor<unknown>>
| ReactFragment
| ReactPortal
) {
return (
<BaseLayout>
<WithSidebarLayout>{page}</WithSidebarLayout>
</BaseLayout>
);
};