fix(comments): cache first comments fetch
This commit is contained in:
parent
99c80855d2
commit
8430a55beb
@ -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 { NDKContextType } from 'contexts/NDKContext'
|
||||||
import { LoaderFunctionArgs, redirect } from 'react-router-dom'
|
import { LoaderFunctionArgs, redirect } from 'react-router-dom'
|
||||||
import { CommentsLoaderResult } from 'types/comments'
|
import { CommentsLoaderResult } from 'types/comments'
|
||||||
@ -24,10 +28,15 @@ export const commentsLoader =
|
|||||||
const replies: NDKEvent[] = []
|
const replies: NDKEvent[] = []
|
||||||
let eTag: string | undefined = replyEvent.tagValue('e')
|
let eTag: string | undefined = replyEvent.tagValue('e')
|
||||||
while (eTag) {
|
while (eTag) {
|
||||||
const prev = await ndkContext.ndk.fetchEvent({
|
const prev = await ndkContext.ndk.fetchEvent(
|
||||||
|
{
|
||||||
kinds: [NDKKind.Text, NDKKind.GenericReply],
|
kinds: [NDKKind.Text, NDKKind.GenericReply],
|
||||||
ids: [eTag]
|
ids: [eTag]
|
||||||
})
|
},
|
||||||
|
{
|
||||||
|
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST
|
||||||
|
}
|
||||||
|
)
|
||||||
if (prev) {
|
if (prev) {
|
||||||
replies.push(prev)
|
replies.push(prev)
|
||||||
eTag = prev.tagValue('e')
|
eTag = prev.tagValue('e')
|
||||||
@ -39,6 +48,7 @@ export const commentsLoader =
|
|||||||
event: replyEvent,
|
event: replyEvent,
|
||||||
parents: replies
|
parents: replies
|
||||||
}
|
}
|
||||||
|
console.log(replyEvent.content)
|
||||||
return result
|
return result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let message = 'An error occurred in fetching comment from relays'
|
let message = 'An error occurred in fetching comment from relays'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user