Create new useSuggestedFollowsByActorWithDismiss hook (#10048)
This commit is contained in:
@@ -12,17 +12,13 @@ import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {type NavigationProp} from '#/lib/routes/types'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {useGetPopularFeedsQuery} from '#/state/queries/feed'
|
||||
import {type FeedDescriptor} from '#/state/queries/post-feed'
|
||||
import {useProfilesQuery} from '#/state/queries/profile'
|
||||
import {
|
||||
suggestedFollowsByActorQueryKey,
|
||||
useSuggestedFollowsByActorQuery,
|
||||
} from '#/state/queries/suggested-follows'
|
||||
import {useSuggestedFollowsByActorWithDismiss} from '#/state/queries/suggested-follows'
|
||||
import {useSession} from '#/state/session'
|
||||
import * as userActionHistory from '#/state/userActionHistory'
|
||||
import {type SeenPost} from '#/state/userActionHistory'
|
||||
@@ -219,43 +215,12 @@ export function SuggestedFollows({feed}: {feed: FeedDescriptor}) {
|
||||
}
|
||||
|
||||
export function SuggestedFollowsProfile({did}: {did: string}) {
|
||||
const {
|
||||
isLoading: isSuggestionsLoading,
|
||||
data,
|
||||
error,
|
||||
} = useSuggestedFollowsByActorQuery({
|
||||
did,
|
||||
})
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const onDismiss = useCallback(
|
||||
(dismissedDid: string) => {
|
||||
queryClient.setQueryData(
|
||||
suggestedFollowsByActorQueryKey(did),
|
||||
(previous: typeof data) => {
|
||||
if (!previous) return previous
|
||||
return {
|
||||
...previous,
|
||||
suggestions: previous.suggestions.filter(
|
||||
s => s.did !== dismissedDid,
|
||||
),
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
[did, queryClient],
|
||||
)
|
||||
|
||||
const profiles = useMemo(() => {
|
||||
return (data?.suggestions ?? []).map(profile => ({
|
||||
actor: profile,
|
||||
recId: data?.recId,
|
||||
}))
|
||||
}, [data?.suggestions, data?.recId])
|
||||
const {profiles, onDismiss, isLoading, error} =
|
||||
useSuggestedFollowsByActorWithDismiss({did})
|
||||
|
||||
return (
|
||||
<ProfileGrid
|
||||
isSuggestionsLoading={isSuggestionsLoading}
|
||||
isSuggestionsLoading={isLoading}
|
||||
profiles={profiles}
|
||||
error={error}
|
||||
viewContext="profile"
|
||||
|
||||
Reference in New Issue
Block a user