add nostr-fetch

This commit is contained in:
Ren Amamiya
2023-07-11 14:27:14 +07:00
parent 339783a1a4
commit 41460436df
11 changed files with 202 additions and 163 deletions

View File

@@ -1,24 +1,22 @@
import { NDKFilter } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
import { useNDK } from '@libs/ndk/provider';
import { Note } from '@shared/notes/note';
import { dateToUnix, getHourAgo } from '@utils/date';
import { nHoursAgo } from '@utils/date';
import { LumeEvent } from '@utils/types';
export function UserFeed({ pubkey }: { pubkey: string }) {
const { ndk } = useNDK();
const { fetcher, relayUrls } = useNDK();
const { status, data } = useQuery(['user-feed', pubkey], async () => {
const now = new Date();
const filter: NDKFilter = {
kinds: [1],
authors: [pubkey],
since: dateToUnix(getHourAgo(48, now)),
};
const events = await ndk.fetchEvents(filter);
return [...events];
const events = await fetcher.fetchAllEvents(
relayUrls,
{ kinds: [1], authors: [pubkey] },
{ since: nHoursAgo(48) },
{ sort: true }
);
return events as unknown as LumeEvent[];
});
return (