diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-11-12 12:45:25 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-12 12:45:25 -0800 |
commit | d9e0a927c1c98ebd6aa3885ab517af27e7de2522 (patch) | |
tree | cee196297391e497f1aa3b650d66633f3a86ca34 /src/state/queries/profile-lists.ts | |
parent | 05b728fffcdb17708fdb52685725faf7fdc545bc (diff) | |
download | voidsky-d9e0a927c1c98ebd6aa3885ab517af27e7de2522.tar.zst |
Refactor lists to use new queries (#1875)
* 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>
Diffstat (limited to 'src/state/queries/profile-lists.ts')
-rw-r--r-- | src/state/queries/profile-lists.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/state/queries/profile-lists.ts b/src/state/queries/profile-lists.ts new file mode 100644 index 000000000..a277a6d61 --- /dev/null +++ b/src/state/queries/profile-lists.ts @@ -0,0 +1,31 @@ +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, + }) +} |