De-closure feed

This commit is contained in:
Paul Frazee
2023-11-28 16:36:41 -08:00
parent 3eafdbefbd
commit 10f48d8947
+24 -30
View File
@@ -6,6 +6,7 @@ import {
QueryKey,
useMutation,
useQueryClient,
QueryFunctionContext,
} from '@tanstack/react-query'
import {
AtUri,
@@ -136,13 +137,17 @@ export function getFeedTypeFromUri(uri: string) {
}
export function useFeedSourceInfoQuery({uri}: {uri: string}) {
const type = getFeedTypeFromUri(uri)
return useQuery({
staleTime: STALE.INFINITY,
queryKey: feedSourceInfoQueryKey({uri}),
queryFn: async () => {
queryFn: feedSourceInfoQueryFn,
})
}
async function feedSourceInfoQueryFn({queryKey}: QueryFunctionContext) {
let view: FeedSourceInfo
const [_, uri] = queryKey as ReturnType<typeof feedSourceInfoQueryKey>
const type = getFeedTypeFromUri(uri)
if (type === 'feed') {
const res = await getAgent().app.bsky.feed.getFeedGenerator({feed: uri})
@@ -156,8 +161,6 @@ export function useFeedSourceInfoQuery({uri}: {uri: string}) {
}
return view
},
})
}
export const isFeedPublicQueryKey = ({uri}: {uri: string}) => [
@@ -168,8 +171,12 @@ export const isFeedPublicQueryKey = ({uri}: {uri: string}) => [
export function useIsFeedPublicQuery({uri}: {uri: string}) {
return useQuery({
queryKey: isFeedPublicQueryKey({uri}),
queryFn: async ({queryKey}) => {
const [, uri] = queryKey
queryFn: isFeedPublicQueryFn,
})
}
async function isFeedPublicQueryFn({queryKey}: QueryFunctionContext) {
const [, uri] = queryKey as ReturnType<typeof isFeedPublicQueryKey>
try {
const res = await getAgent().app.bsky.feed.getFeed({
feed: uri,
@@ -188,8 +195,6 @@ export function useIsFeedPublicQuery({uri}: {uri: string}) {
return true
}
},
})
}
export const useGetPopularFeedsQueryKey = ['getPopularFeeds']
@@ -203,16 +208,20 @@ export function useGetPopularFeedsQuery() {
string | undefined
>({
queryKey: useGetPopularFeedsQueryKey,
queryFn: async ({pageParam}) => {
queryFn: getPopularFeedsQueryFn,
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
})
}
async function getPopularFeedsQueryFn({
pageParam,
}: QueryFunctionContext<QueryKey, string | undefined>) {
const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({
limit: 10,
cursor: pageParam,
})
return res.data
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
})
}
export function useSearchPopularFeedsMutation() {
@@ -271,22 +280,7 @@ export function usePinnedFeedsInfos(): FeedSourceInfo[] {
reqs.push(
queryClient.fetchQuery({
queryKey: feedSourceInfoQueryKey({uri}),
queryFn: async () => {
const type = getFeedTypeFromUri(uri)
if (type === 'feed') {
const res = await getAgent().app.bsky.feed.getFeedGenerator({
feed: uri,
})
return hydrateFeedGenerator(res.data.view)
} else {
const res = await getAgent().app.bsky.graph.getList({
list: uri,
limit: 1,
})
return hydrateList(res.data.list)
}
},
queryFn: feedSourceInfoQueryFn,
}),
)
}