fix(comments): cache first comments fetch

This commit is contained in:
en 2025-01-30 09:34:34 +01:00
parent 99c80855d2
commit 8430a55beb

View File

@ -1,4 +1,8 @@
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'
import {
NDKEvent,
NDKKind,
NDKSubscriptionCacheUsage
} from '@nostr-dev-kit/ndk'
import { NDKContextType } from 'contexts/NDKContext'
import { LoaderFunctionArgs, redirect } from 'react-router-dom'
import { CommentsLoaderResult } from 'types/comments'
@ -24,10 +28,15 @@ export const commentsLoader =
const replies: NDKEvent[] = []
let eTag: string | undefined = replyEvent.tagValue('e')
while (eTag) {
const prev = await ndkContext.ndk.fetchEvent({
kinds: [NDKKind.Text, NDKKind.GenericReply],
ids: [eTag]
})
const prev = await ndkContext.ndk.fetchEvent(
{
kinds: [NDKKind.Text, NDKKind.GenericReply],
ids: [eTag]
},
{
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST
}
)
if (prev) {
replies.push(prev)
eTag = prev.tagValue('e')
@ -39,6 +48,7 @@ export const commentsLoader =
event: replyEvent,
parents: replies
}
console.log(replyEvent.content)
return result
} catch (error) {
let message = 'An error occurred in fetching comment from relays'