De-closure feed
This commit is contained in:
+24
-30
@@ -6,6 +6,7 @@ import {
|
|||||||
QueryKey,
|
QueryKey,
|
||||||
useMutation,
|
useMutation,
|
||||||
useQueryClient,
|
useQueryClient,
|
||||||
|
QueryFunctionContext,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
import {
|
import {
|
||||||
AtUri,
|
AtUri,
|
||||||
@@ -136,13 +137,17 @@ export function getFeedTypeFromUri(uri: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
||||||
const type = getFeedTypeFromUri(uri)
|
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
staleTime: STALE.INFINITY,
|
staleTime: STALE.INFINITY,
|
||||||
queryKey: feedSourceInfoQueryKey({uri}),
|
queryKey: feedSourceInfoQueryKey({uri}),
|
||||||
queryFn: async () => {
|
queryFn: feedSourceInfoQueryFn,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function feedSourceInfoQueryFn({queryKey}: QueryFunctionContext) {
|
||||||
let view: FeedSourceInfo
|
let view: FeedSourceInfo
|
||||||
|
const [_, uri] = queryKey as ReturnType<typeof feedSourceInfoQueryKey>
|
||||||
|
const type = getFeedTypeFromUri(uri)
|
||||||
|
|
||||||
if (type === 'feed') {
|
if (type === 'feed') {
|
||||||
const res = await getAgent().app.bsky.feed.getFeedGenerator({feed: uri})
|
const res = await getAgent().app.bsky.feed.getFeedGenerator({feed: uri})
|
||||||
@@ -156,8 +161,6 @@ export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return view
|
return view
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isFeedPublicQueryKey = ({uri}: {uri: string}) => [
|
export const isFeedPublicQueryKey = ({uri}: {uri: string}) => [
|
||||||
@@ -168,8 +171,12 @@ export const isFeedPublicQueryKey = ({uri}: {uri: string}) => [
|
|||||||
export function useIsFeedPublicQuery({uri}: {uri: string}) {
|
export function useIsFeedPublicQuery({uri}: {uri: string}) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: isFeedPublicQueryKey({uri}),
|
queryKey: isFeedPublicQueryKey({uri}),
|
||||||
queryFn: async ({queryKey}) => {
|
queryFn: isFeedPublicQueryFn,
|
||||||
const [, uri] = queryKey
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function isFeedPublicQueryFn({queryKey}: QueryFunctionContext) {
|
||||||
|
const [, uri] = queryKey as ReturnType<typeof isFeedPublicQueryKey>
|
||||||
try {
|
try {
|
||||||
const res = await getAgent().app.bsky.feed.getFeed({
|
const res = await getAgent().app.bsky.feed.getFeed({
|
||||||
feed: uri,
|
feed: uri,
|
||||||
@@ -188,8 +195,6 @@ export function useIsFeedPublicQuery({uri}: {uri: string}) {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useGetPopularFeedsQueryKey = ['getPopularFeeds']
|
export const useGetPopularFeedsQueryKey = ['getPopularFeeds']
|
||||||
@@ -203,16 +208,20 @@ export function useGetPopularFeedsQuery() {
|
|||||||
string | undefined
|
string | undefined
|
||||||
>({
|
>({
|
||||||
queryKey: useGetPopularFeedsQueryKey,
|
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({
|
const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({
|
||||||
limit: 10,
|
limit: 10,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
})
|
})
|
||||||
return res.data
|
return res.data
|
||||||
},
|
|
||||||
initialPageParam: undefined,
|
|
||||||
getNextPageParam: lastPage => lastPage.cursor,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSearchPopularFeedsMutation() {
|
export function useSearchPopularFeedsMutation() {
|
||||||
@@ -271,22 +280,7 @@ export function usePinnedFeedsInfos(): FeedSourceInfo[] {
|
|||||||
reqs.push(
|
reqs.push(
|
||||||
queryClient.fetchQuery({
|
queryClient.fetchQuery({
|
||||||
queryKey: feedSourceInfoQueryKey({uri}),
|
queryKey: feedSourceInfoQueryKey({uri}),
|
||||||
queryFn: async () => {
|
queryFn: feedSourceInfoQueryFn,
|
||||||
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)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user