Bluesky app fork with some witchin' additions 馃挮
at main 81 lines 2.0 kB view raw
1import {type QueryClient, useInfiniteQuery} from '@tanstack/react-query' 2 3import {useAgent} from '#/state/session' 4 5export const RQKEY_ROOT = 'actor-starter-packs' 6export const RQKEY_WITH_MEMBERSHIP_ROOT = 'actor-starter-packs-with-membership' 7export const RQKEY = (did?: string) => [RQKEY_ROOT, did] 8export const RQKEY_WITH_MEMBERSHIP = (did?: string) => [ 9 RQKEY_WITH_MEMBERSHIP_ROOT, 10 did, 11] 12 13export function useActorStarterPacksQuery({ 14 did, 15 enabled = true, 16}: { 17 did?: string 18 enabled?: boolean 19}) { 20 const agent = useAgent() 21 22 return useInfiniteQuery({ 23 queryKey: RQKEY(did), 24 queryFn: async ({pageParam}: {pageParam?: string}) => { 25 const res = await agent.app.bsky.graph.getActorStarterPacks({ 26 actor: did!, 27 limit: 10, 28 cursor: pageParam, 29 }) 30 return res.data 31 }, 32 enabled: Boolean(did) && enabled, 33 initialPageParam: undefined, 34 getNextPageParam: lastPage => lastPage.cursor, 35 }) 36} 37 38export function useActorStarterPacksWithMembershipsQuery({ 39 did, 40 enabled = true, 41}: { 42 did?: string 43 enabled?: boolean 44}) { 45 const agent = useAgent() 46 47 return useInfiniteQuery({ 48 queryKey: RQKEY_WITH_MEMBERSHIP(did), 49 queryFn: async ({pageParam}: {pageParam?: string}) => { 50 const res = await agent.app.bsky.graph.getStarterPacksWithMembership({ 51 actor: did!, 52 limit: 10, 53 cursor: pageParam, 54 }) 55 return res.data 56 }, 57 enabled: Boolean(did) && enabled, 58 initialPageParam: undefined, 59 getNextPageParam: lastPage => lastPage.cursor, 60 }) 61} 62 63export async function invalidateActorStarterPacksQuery({ 64 queryClient, 65 did, 66}: { 67 queryClient: QueryClient 68 did: string 69}) { 70 await queryClient.invalidateQueries({queryKey: RQKEY(did)}) 71} 72 73export async function invalidateActorStarterPacksWithMembershipQuery({ 74 queryClient, 75 did, 76}: { 77 queryClient: QueryClient 78 did: string 79}) { 80 await queryClient.invalidateQueries({queryKey: RQKEY_WITH_MEMBERSHIP(did)}) 81}