Skip to content

Commit

Permalink
delete useMyFollowsQuery (#3529)
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzius authored Apr 17, 2024
1 parent d598289 commit a2df814
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 80 deletions.
36 changes: 3 additions & 33 deletions src/state/queries/actor-autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {AppBskyActorDefs, moderateProfile, ModerationOpts} from '@atproto/api'
import {useQuery, useQueryClient} from '@tanstack/react-query'

import {isJustAMute} from '#/lib/moderation'
import {isInvalidHandle} from '#/lib/strings/handles'
import {logger} from '#/logger'
import {STALE} from '#/state/queries'
import {useMyFollowsQuery} from '#/state/queries/my-follows'
import {getAgent} from '#/state/session'
import {DEFAULT_LOGGED_OUT_PREFERENCES, useModerationOpts} from './preferences'

Expand All @@ -19,7 +17,6 @@ const RQKEY_ROOT = 'actor-autocomplete'
export const RQKEY = (prefix: string) => [RQKEY_ROOT, prefix]

export function useActorAutocompleteQuery(prefix: string) {
const {data: follows, isFetching} = useMyFollowsQuery()
const moderationOpts = useModerationOpts()

prefix = prefix.toLowerCase()
Expand All @@ -36,25 +33,18 @@ export function useActorAutocompleteQuery(prefix: string) {
: undefined
return res?.data.actors || []
},
enabled: !isFetching,
select: React.useCallback(
(data: AppBskyActorDefs.ProfileViewBasic[]) => {
return computeSuggestions(
prefix,
follows,
data,
moderationOpts || DEFAULT_MOD_OPTS,
)
return computeSuggestions(data, moderationOpts || DEFAULT_MOD_OPTS)
},
[prefix, follows, moderationOpts],
[moderationOpts],
),
})
}

export type ActorAutocompleteFn = ReturnType<typeof useActorAutocompleteFn>
export function useActorAutocompleteFn() {
const queryClient = useQueryClient()
const {data: follows} = useMyFollowsQuery()
const moderationOpts = useModerationOpts()

return React.useCallback(
Expand All @@ -80,26 +70,19 @@ export function useActorAutocompleteFn() {
}

return computeSuggestions(
query,
follows,
res?.data.actors,
moderationOpts || DEFAULT_MOD_OPTS,
)
},
[follows, queryClient, moderationOpts],
[queryClient, moderationOpts],
)
}

function computeSuggestions(
prefix: string,
follows: AppBskyActorDefs.ProfileViewBasic[] | undefined,
searched: AppBskyActorDefs.ProfileViewBasic[] = [],
moderationOpts: ModerationOpts,
) {
let items: AppBskyActorDefs.ProfileViewBasic[] = []
if (follows) {
items = follows.filter(follow => prefixMatch(prefix, follow)).slice(0, 8)
}
for (const item of searched) {
if (!items.find(item2 => item2.handle === item.handle)) {
items.push(item)
Expand All @@ -110,16 +93,3 @@ function computeSuggestions(
return !modui.filter || isJustAMute(modui)
})
}

function prefixMatch(
prefix: string,
info: AppBskyActorDefs.ProfileViewBasic,
): boolean {
if (!isInvalidHandle(info.handle) && info.handle.includes(prefix)) {
return true
}
if (info.displayName?.toLocaleLowerCase().includes(prefix)) {
return true
}
return false
}
47 changes: 0 additions & 47 deletions src/state/queries/my-follows.ts

This file was deleted.

0 comments on commit a2df814

Please sign in to comment.