Bluesky app fork with some witchin' additions 馃挮
at feat/markdown-basic 56 lines 1.5 kB view raw
1import {type AppBskyGraphGetLists, moderateUserList} from '@atproto/api' 2import { 3 type InfiniteData, 4 type QueryKey, 5 useInfiniteQuery, 6} from '@tanstack/react-query' 7 8import {useAgent} from '#/state/session' 9import {useModerationOpts} from '../preferences/moderation-opts' 10 11const PAGE_SIZE = 30 12type RQPageParam = string | undefined 13 14export const RQKEY_ROOT = 'profile-lists' 15export const RQKEY = (did: string) => [RQKEY_ROOT, did] 16 17export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) { 18 const moderationOpts = useModerationOpts() 19 const enabled = opts?.enabled !== false && Boolean(moderationOpts) 20 const agent = useAgent() 21 return useInfiniteQuery< 22 AppBskyGraphGetLists.OutputSchema, 23 Error, 24 InfiniteData<AppBskyGraphGetLists.OutputSchema>, 25 QueryKey, 26 RQPageParam 27 >({ 28 queryKey: RQKEY(did), 29 async queryFn({pageParam}: {pageParam: RQPageParam}) { 30 const res = await agent.app.bsky.graph.getLists({ 31 actor: did, 32 limit: PAGE_SIZE, 33 cursor: pageParam, 34 }) 35 36 return res.data 37 }, 38 initialPageParam: undefined, 39 getNextPageParam: lastPage => lastPage.cursor, 40 enabled, 41 select(data) { 42 return { 43 ...data, 44 pages: data.pages.map(page => { 45 return { 46 ...page, 47 lists: page.lists.filter(list => { 48 const decision = moderateUserList(list, moderationOpts!) 49 return !decision.ui('contentList').filter 50 }), 51 } 52 }), 53 } 54 }, 55 }) 56}