Bluesky app fork with some witchin' additions 馃挮
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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