Enable show less / more buttons for third party feeds (#8672)
Co-authored-by: hailey <hailey@blueskyweb.xyz> Co-authored-by: Hailey <me@haileyok.com>
This commit is contained in:
@@ -48,6 +48,7 @@ export type FeedSourceFeedInfo = {
|
||||
creatorDid: string
|
||||
creatorHandle: string
|
||||
likeCount: number | undefined
|
||||
acceptsInteractions?: boolean
|
||||
likeUri: string | undefined
|
||||
contentMode: AppBskyFeedDefs.GeneratorView['contentMode']
|
||||
}
|
||||
@@ -73,6 +74,12 @@ export type FeedSourceListInfo = {
|
||||
|
||||
export type FeedSourceInfo = FeedSourceFeedInfo | FeedSourceListInfo
|
||||
|
||||
export function isFeedSourceFeedInfo(
|
||||
feed: FeedSourceInfo,
|
||||
): feed is FeedSourceFeedInfo {
|
||||
return feed.type === 'feed'
|
||||
}
|
||||
|
||||
const feedSourceInfoQueryKeyRoot = 'getFeedSourceInfo'
|
||||
export const feedSourceInfoQueryKey = ({uri}: {uri: string}) => [
|
||||
feedSourceInfoQueryKeyRoot,
|
||||
@@ -115,6 +122,7 @@ export function hydrateFeedGenerator(
|
||||
creatorDid: view.creator.did,
|
||||
creatorHandle: view.creator.handle,
|
||||
likeCount: view.likeCount,
|
||||
acceptsInteractions: view.acceptsInteractions,
|
||||
likeUri: view.viewer?.like,
|
||||
contentMode: view.contentMode,
|
||||
}
|
||||
@@ -619,6 +627,29 @@ export function useSavedFeeds() {
|
||||
})
|
||||
}
|
||||
|
||||
const feedInfoQueryKeyRoot = 'feedInfo'
|
||||
|
||||
export function useFeedInfo(feedUri: string | undefined) {
|
||||
const agent = useAgent()
|
||||
|
||||
return useQuery({
|
||||
staleTime: STALE.INFINITY,
|
||||
queryKey: [feedInfoQueryKeyRoot, feedUri],
|
||||
queryFn: async () => {
|
||||
if (!feedUri) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const res = await agent.app.bsky.feed.getFeedGenerator({
|
||||
feed: feedUri,
|
||||
})
|
||||
|
||||
const feedSourceInfo = hydrateFeedGenerator(res.data.view)
|
||||
return feedSourceInfo
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function precacheFeed(queryClient: QueryClient, hydratedFeed: FeedSourceInfo) {
|
||||
precacheResolvedUri(
|
||||
queryClient,
|
||||
|
||||
Reference in New Issue
Block a user