Create new useSuggestedFollowsByActorWithDismiss hook (#10048)

This commit is contained in:
DS Boyce
2026-03-13 09:18:23 -07:00
committed by GitHub
parent 6afe48db6a
commit 97fdd7c59b
3 changed files with 58 additions and 87 deletions
@@ -1,14 +1,7 @@
import {useCallback, useMemo} from 'react'
import {useQueryClient} from '@tanstack/react-query'
import {AccordionAnimation} from '#/lib/custom-animations/AccordionAnimation'
import {
suggestedFollowsByActorQueryKey,
useSuggestedFollowsByActorQuery,
} from '#/state/queries/suggested-follows'
import {useSuggestedFollowsByActorWithDismiss} from '#/state/queries/suggested-follows'
import {ProfileGrid} from '#/components/FeedInterstitials'
import {IS_ANDROID} from '#/env'
import type * as bsky from '#/types/bsky'
export function ProfileHeaderSuggestedFollows({
isExpanded,
@@ -20,7 +13,7 @@ export function ProfileHeaderSuggestedFollows({
onRequestHide: () => void
}) {
const {profiles, onDismiss, isLoading, error} =
useProfileHeaderSuggestions(actorDid)
useSuggestedFollowsByActorWithDismiss({did: actorDid})
/* NOTE (caidanw):
* Android does not work well with this feature yet.
@@ -44,42 +37,3 @@ export function ProfileHeaderSuggestedFollows({
</AccordionAnimation>
)
}
function useProfileHeaderSuggestions(actorDid: string) {
const {isLoading, data, error} = useSuggestedFollowsByActorQuery({
did: actorDid,
})
const queryClient = useQueryClient()
const onDismiss = useCallback(
(dismissedDid: string) => {
queryClient.setQueryData(
suggestedFollowsByActorQueryKey(actorDid),
(previous: typeof data) => {
if (!previous) return previous
return {
...previous,
suggestions: previous.suggestions.filter(
s => s.did !== dismissedDid,
),
}
},
)
},
[actorDid, queryClient],
)
const profiles = useMemo(() => {
return (data?.suggestions ?? []).map(profile => ({
actor: profile as bsky.profile.AnyProfileView,
recId: data?.recId,
}))
}, [data?.suggestions, data?.recId])
return {
profiles,
onDismiss,
isLoading,
error,
}
}