Files
bsky-social-app/src/state/queries/profile-feedgens.ts
T
Samuel Newman 300a50b69a migrate runtime call sites to lex clients and sdk actions
Phase 3 tasks 3-7 (parallel wave): composer/post pipeline on
pdsClient/appviewClient with structural+instance blob guards and a golden
CID fixture test; chat Convo/EventBus/queries on the dedicated chat client;
preferences sugar to SDK actions on the PDS client; remaining state/queries
producers (usePostThread unspecced flip, video scoped-token clients,
notifications, starter packs, lists) to client.call; UI runtime sweep
(AtUri from @atproto/syntax, moderation fns from @bsky.app/sdk/moderation,
SDK RichText, ozone reason tokens, guard rewrites via #/types/bsky).

Intermediate checkpoint (hooks skipped): ~114 typecheck errors remain in
cross-boundary consumer files, resolved by the type-only codemod next.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-30 18:12:10 +03:00

69 lines
1.9 KiB
TypeScript

import {type AtIdentifierString} from '@atproto/syntax'
import {moderateFeedGenerator} from '@bsky.app/sdk/moderation'
import {
type InfiniteData,
type QueryKey,
useInfiniteQuery,
} from '@tanstack/react-query'
import {useAppviewClient} from '#/state/session'
import {app} from '#/lexicons'
import {useModerationOpts} from '../preferences/moderation-opts'
const PAGE_SIZE = 50
type RQPageParam = string | undefined
// TODO refactor invalidate on mutate?
export const RQKEY_ROOT = 'profile-feedgens'
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
export function useProfileFeedgensQuery(
did: string,
opts?: {enabled?: boolean},
) {
const moderationOpts = useModerationOpts()
const enabled = opts?.enabled !== false && Boolean(moderationOpts)
const client = useAppviewClient()
return useInfiniteQuery<
app.bsky.feed.getActorFeeds.$OutputBody,
Error,
InfiniteData<app.bsky.feed.getActorFeeds.$OutputBody>,
QueryKey,
RQPageParam
>({
queryKey: RQKEY(did),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const data = await client.call(app.bsky.feed.getActorFeeds, {
actor: did as AtIdentifierString,
limit: PAGE_SIZE,
cursor: pageParam,
})
data.feeds.sort((a, b) => {
return (b.likeCount || 0) - (a.likeCount || 0)
})
return data
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
enabled,
select(data) {
return {
...data,
pages: data.pages.map(page => {
return {
...page,
feeds: page.feeds
// filter by labels
.filter(list => {
const decision = moderateFeedGenerator(list, moderationOpts!)
return !decision
.ui('contentList')
.filters.some(cause => cause.type !== 'muted')
}),
}
}),
}
},
})
}