This commit is contained in:
2023-12-06 08:08:11 +07:00
parent 4006c0010e
commit 24c2ed4eb2
3 changed files with 25 additions and 13 deletions

View File

@@ -308,7 +308,7 @@ export default function App() {
router={router}
fallbackElement={
<div className="flex h-full w-full items-center justify-center">
<LoaderIcon className="h-6 w-6 animate-spin text-white" />
<LoaderIcon className="h-6 w-6 animate-spin" />
</div>
}
future={{ v7_startTransition: true }}

View File

@@ -1,4 +1,4 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { NDKEvent, NDKSubscriptionCacheUsage, NostrEvent } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
import { nip19 } from 'nostr-tools';
import { AddressPointer } from 'nostr-tools/lib/types/nip19';
@@ -30,20 +30,26 @@ export function useEvent(id: undefined | string, embed?: undefined | string) {
// return embed event (nostr.band api)
if (embed) {
const event: NDKEvent = JSON.parse(embed);
return event;
const embedEvent: NostrEvent = JSON.parse(embed);
const ndkEvent = new NDKEvent(ndk, embedEvent);
return ndkEvent;
}
// get event from relay
const event = await ndk.fetchEvent(id);
const event = await ndk.fetchEvent(id, {
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST,
});
if (!event)
throw new Error(`Cannot get event with ${id}, will be retry after 10 seconds`);
if (!event) throw new Error('event not found');
return event;
},
staleTime: Infinity,
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnReconnect: false,
retry: 2,
});
return { status, isFetching, isError, data };

View File

@@ -1,4 +1,4 @@
import { NDKUserProfile } from '@nostr-dev-kit/ndk';
import { NDKSubscriptionCacheUsage, NDKUserProfile } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
import { nip19 } from 'nostr-tools';
@@ -30,15 +30,21 @@ export function useProfile(pubkey: string, embed?: string) {
}
const user = ndk.getUser({ pubkey: hexstring });
const profile = await user.fetchProfile();
const profile = await user.fetchProfile({
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST,
});
if (!profile)
throw new Error(
`Cannot get metadata for ${pubkey}, will be retry after 10 seconds`
);
return profile;
} catch (e) {
console.error(e);
throw new Error(
`Cannot get metadata for ${pubkey}, will be retry after 10 seconds`
);
throw new Error(e);
}
},
refetchOnMount: false,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
retry: 2,