* Refactor lists queries to react-query * Delete old lists-list model * Implement list, list-members, and list-memberships react-queries * Update CreateOrEditList modal * First pass at my-follows and actor-autocomplete queries * Update ListAddUserModal to use new queries, change to ListAddRemoveUsersModal * Update UserAddRemoveLists modal * Remove old TODO * Fix indent, autocomplete query * Add a todo --------- Co-authored-by: Eric Bailey <git@esb.lol>
31 lines
882 B
TypeScript
31 lines
882 B
TypeScript
import {AppBskyGraphGetLists} 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-lists', did]
|
|
|
|
export function useProfileListsQuery(did: string) {
|
|
const {agent} = useSession()
|
|
return useInfiniteQuery<
|
|
AppBskyGraphGetLists.OutputSchema,
|
|
Error,
|
|
InfiniteData<AppBskyGraphGetLists.OutputSchema>,
|
|
QueryKey,
|
|
RQPageParam
|
|
>({
|
|
queryKey: RQKEY(did),
|
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
|
const res = await agent.app.bsky.graph.getLists({
|
|
actor: did,
|
|
limit: PAGE_SIZE,
|
|
cursor: pageParam,
|
|
})
|
|
return res.data
|
|
},
|
|
initialPageParam: undefined,
|
|
getNextPageParam: lastPage => lastPage.cursor,
|
|
})
|
|
}
|