* Only fetch profile tab content when focused * Fix keys * Add missing behaviors to post tabs * Delete old profile mobx model
36 lines
994 B
TypeScript
36 lines
994 B
TypeScript
import {AppBskyFeedGetActorFeeds} from '@atproto/api'
|
|
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
|
|
import {useSession} from '../session'
|
|
|
|
const PAGE_SIZE = 30
|
|
type RQPageParam = string | undefined
|
|
|
|
export const RQKEY = (did: string) => ['profile-feedgens', did]
|
|
|
|
export function useProfileFeedgensQuery(
|
|
did: string,
|
|
opts?: {enabled?: boolean},
|
|
) {
|
|
const {agent} = useSession()
|
|
const enabled = opts?.enabled !== false
|
|
return useInfiniteQuery<
|
|
AppBskyFeedGetActorFeeds.OutputSchema,
|
|
Error,
|
|
InfiniteData<AppBskyFeedGetActorFeeds.OutputSchema>,
|
|
QueryKey,
|
|
RQPageParam
|
|
>({
|
|
queryKey: RQKEY(did),
|
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
|
const res = await agent.app.bsky.feed.getActorFeeds({
|
|
actor: did,
|
|
limit: PAGE_SIZE,
|
|
cursor: pageParam,
|
|
})
|
|
return res.data
|
|
},
|
|
initialPageParam: undefined,
|
|
getNextPageParam: lastPage => lastPage.cursor,
|
|
enabled,
|
|
})
|
|
}
|