Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

delete useMyFollowsQuery (#3529)

authored by

Samuel Newman and committed by
GitHub
a2df8141 d5982891

+3 -80
+3 -33
src/state/queries/actor-autocomplete.ts
··· 3 3 import {useQuery, useQueryClient} from '@tanstack/react-query' 4 4 5 5 import {isJustAMute} from '#/lib/moderation' 6 - import {isInvalidHandle} from '#/lib/strings/handles' 7 6 import {logger} from '#/logger' 8 7 import {STALE} from '#/state/queries' 9 - import {useMyFollowsQuery} from '#/state/queries/my-follows' 10 8 import {getAgent} from '#/state/session' 11 9 import {DEFAULT_LOGGED_OUT_PREFERENCES, useModerationOpts} from './preferences' 12 10 ··· 19 17 export const RQKEY = (prefix: string) => [RQKEY_ROOT, prefix] 20 18 21 19 export function useActorAutocompleteQuery(prefix: string) { 22 - const {data: follows, isFetching} = useMyFollowsQuery() 23 20 const moderationOpts = useModerationOpts() 24 21 25 22 prefix = prefix.toLowerCase() ··· 36 33 : undefined 37 34 return res?.data.actors || [] 38 35 }, 39 - enabled: !isFetching, 40 36 select: React.useCallback( 41 37 (data: AppBskyActorDefs.ProfileViewBasic[]) => { 42 - return computeSuggestions( 43 - prefix, 44 - follows, 45 - data, 46 - moderationOpts || DEFAULT_MOD_OPTS, 47 - ) 38 + return computeSuggestions(data, moderationOpts || DEFAULT_MOD_OPTS) 48 39 }, 49 - [prefix, follows, moderationOpts], 40 + [moderationOpts], 50 41 ), 51 42 }) 52 43 } ··· 54 45 export type ActorAutocompleteFn = ReturnType<typeof useActorAutocompleteFn> 55 46 export function useActorAutocompleteFn() { 56 47 const queryClient = useQueryClient() 57 - const {data: follows} = useMyFollowsQuery() 58 48 const moderationOpts = useModerationOpts() 59 49 60 50 return React.useCallback( ··· 80 70 } 81 71 82 72 return computeSuggestions( 83 - query, 84 - follows, 85 73 res?.data.actors, 86 74 moderationOpts || DEFAULT_MOD_OPTS, 87 75 ) 88 76 }, 89 - [follows, queryClient, moderationOpts], 77 + [queryClient, moderationOpts], 90 78 ) 91 79 } 92 80 93 81 function computeSuggestions( 94 - prefix: string, 95 - follows: AppBskyActorDefs.ProfileViewBasic[] | undefined, 96 82 searched: AppBskyActorDefs.ProfileViewBasic[] = [], 97 83 moderationOpts: ModerationOpts, 98 84 ) { 99 85 let items: AppBskyActorDefs.ProfileViewBasic[] = [] 100 - if (follows) { 101 - items = follows.filter(follow => prefixMatch(prefix, follow)).slice(0, 8) 102 - } 103 86 for (const item of searched) { 104 87 if (!items.find(item2 => item2.handle === item.handle)) { 105 88 items.push(item) ··· 110 93 return !modui.filter || isJustAMute(modui) 111 94 }) 112 95 } 113 - 114 - function prefixMatch( 115 - prefix: string, 116 - info: AppBskyActorDefs.ProfileViewBasic, 117 - ): boolean { 118 - if (!isInvalidHandle(info.handle) && info.handle.includes(prefix)) { 119 - return true 120 - } 121 - if (info.displayName?.toLocaleLowerCase().includes(prefix)) { 122 - return true 123 - } 124 - return false 125 - }
-47
src/state/queries/my-follows.ts
··· 1 - import {AppBskyActorDefs} from '@atproto/api' 2 - import {useQuery} from '@tanstack/react-query' 3 - 4 - import {STALE} from '#/state/queries' 5 - import {getAgent, useSession} from '../session' 6 - 7 - // sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records 8 - const SANITY_PAGE_LIMIT = 1000 9 - const PAGE_SIZE = 100 10 - // ...which comes 10,000k follows 11 - 12 - const RQKEY_ROOT = 'my-follows' 13 - export const RQKEY = () => [RQKEY_ROOT] 14 - 15 - export function useMyFollowsQuery() { 16 - const {currentAccount} = useSession() 17 - return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({ 18 - staleTime: STALE.MINUTES.ONE, 19 - queryKey: RQKEY(), 20 - async queryFn() { 21 - if (!currentAccount) { 22 - return [] 23 - } 24 - let cursor 25 - let arr: AppBskyActorDefs.ProfileViewBasic[] = [] 26 - for (let i = 0; i < SANITY_PAGE_LIMIT; i++) { 27 - const res = await getAgent().getFollows({ 28 - actor: currentAccount.did, 29 - cursor, 30 - limit: PAGE_SIZE, 31 - }) 32 - // TODO 33 - // res.data.follows = res.data.follows.filter( 34 - // profile => 35 - // !moderateProfile(profile, this.rootStore.preferences.moderationOpts) 36 - // .account.filter, 37 - // ) 38 - arr = arr.concat(res.data.follows) 39 - if (!res.data.cursor) { 40 - break 41 - } 42 - cursor = res.data.cursor 43 - } 44 - return arr 45 - }, 46 - }) 47 - }