Bluesky app fork with some witchin' additions 馃挮
at linkat-integration 65 lines 1.9 kB view raw
1import {useMemo} from 'react' 2 3import {useInterestsDisplayNames} from '#/lib/interests' 4import {useActorSearch} from '#/state/queries/actor-search' 5import {useGetSuggestedUsersQuery} from '#/state/queries/trending/useGetSuggestedUsersQuery' 6 7/** 8 * Conditional hook, used in case a user is a non-english speaker, in which 9 * case we fall back to searching for users instead of our more curated set. 10 */ 11export function useSuggestedUsers({ 12 category = null, 13 search = false, 14 overrideInterests, 15}: { 16 category?: string | null 17 /** 18 * If true, we'll search for users using the translated value of `category`, 19 * based on the user's "app language setting 20 */ 21 search?: boolean 22 /** 23 * In onboarding, interests haven't been saved to prefs yet, so we need to 24 * pass them down through here 25 */ 26 overrideInterests?: string[] 27}) { 28 const interestsDisplayNames = useInterestsDisplayNames() 29 const curated = useGetSuggestedUsersQuery({ 30 enabled: !search, 31 category, 32 overrideInterests, 33 }) 34 const searched = useActorSearch({ 35 enabled: !!search, 36 // use user's app language translation for this value 37 query: category ? interestsDisplayNames[category] : '', 38 limit: 10, 39 }) 40 41 return useMemo(() => { 42 if (search) { 43 return { 44 // we're not paginating right now 45 data: searched?.data 46 ? { 47 actors: searched.data.pages.flatMap(p => p.actors) ?? [], 48 } 49 : undefined, 50 isLoading: searched.isLoading, 51 error: searched.error, 52 isRefetching: searched.isRefetching, 53 refetch: searched.refetch, 54 } 55 } else { 56 return { 57 data: curated.data, 58 isLoading: curated.isLoading, 59 error: curated.error, 60 isRefetching: curated.isRefetching, 61 refetch: curated.refetch, 62 } 63 } 64 }, [curated, searched, search]) 65}