wip: refactor

This commit is contained in:
Ren Amamiya
2023-08-18 07:37:11 +07:00
parent 414dd50a5c
commit 5626579b3f
17 changed files with 156 additions and 307 deletions

View File

@@ -4,6 +4,7 @@ import { useQuery } from '@tanstack/react-query';
import { useNDK } from '@libs/ndk/provider';
import { parser } from '@utils/parser';
import { RichContent } from '@utils/types';
export function useEvent(id: string, embed?: string) {
const { ndk } = useNDK();
@@ -12,18 +13,18 @@ export function useEvent(id: string, embed?: string) {
async () => {
if (embed) {
const event: NDKEvent = JSON.parse(embed);
// @ts-expect-error, #TODO: convert NDKEvent to ExNDKEvent
if (event.kind === 1) event.content = parser(event);
let richContent: RichContent;
if (event.kind === 1) richContent = parser(event);
return event as unknown as NDKEvent;
return { event: event as NDKEvent, richContent: richContent };
}
const event = (await ndk.fetchEvent(id)) as NDKEvent;
if (!event) throw new Error('event not found');
// @ts-expect-error, #TODO: convert NDKEvent to ExNDKEvent
if (event.kind === 1) event.content = parser(event);
let richContent: RichContent;
if (event.kind === 1) richContent = parser(event);
return event as NDKEvent;
return { event: event as NDKEvent, richContent: richContent };
},
{
staleTime: Infinity,