[SDK] Migrate profile and graph read queries to the appview client (#11356)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
import {
|
||||
type AppBskyFeedGetActorFeeds,
|
||||
moderateFeedGenerator,
|
||||
} from '@atproto/api'
|
||||
import {moderateFeedGenerator} from '@atproto/api'
|
||||
import {type DidString} from '@atproto/syntax'
|
||||
import {
|
||||
type InfiniteData,
|
||||
type QueryKey,
|
||||
useInfiniteQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {useAgent} from '#/state/session'
|
||||
import {useAppviewClient} from '#/state/session'
|
||||
import {app} from '#/lexicons'
|
||||
import {useModerationOpts} from '../preferences/moderation-opts'
|
||||
|
||||
const PAGE_SIZE = 50
|
||||
@@ -24,25 +23,25 @@ export function useProfileFeedgensQuery(
|
||||
) {
|
||||
const moderationOpts = useModerationOpts()
|
||||
const enabled = opts?.enabled !== false && Boolean(moderationOpts)
|
||||
const agent = useAgent()
|
||||
const client = useAppviewClient()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedGetActorFeeds.OutputSchema,
|
||||
app.bsky.feed.getActorFeeds.$OutputBody,
|
||||
Error,
|
||||
InfiniteData<AppBskyFeedGetActorFeeds.OutputSchema>,
|
||||
InfiniteData<app.bsky.feed.getActorFeeds.$OutputBody>,
|
||||
QueryKey,
|
||||
RQPageParam
|
||||
>({
|
||||
queryKey: RQKEY(did),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await agent.app.bsky.feed.getActorFeeds({
|
||||
actor: did,
|
||||
const data = await client.call(app.bsky.feed.getActorFeeds, {
|
||||
actor: did as DidString,
|
||||
limit: PAGE_SIZE,
|
||||
cursor: pageParam,
|
||||
})
|
||||
res.data.feeds.sort((a, b) => {
|
||||
data.feeds.sort((a, b) => {
|
||||
return (b.likeCount || 0) - (a.likeCount || 0)
|
||||
})
|
||||
return res.data
|
||||
return data
|
||||
},
|
||||
initialPageParam: undefined,
|
||||
getNextPageParam: lastPage => lastPage.cursor,
|
||||
|
||||
Reference in New Issue
Block a user