dont filter exact matches from typeahead (#4802)

zio/stable
Hailey 2024-07-19 15:25:09 -07:00 committed by GitHub
parent 3627a249ff
commit 59bafb426f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 11 deletions

View File

@ -45,9 +45,13 @@ export function useActorAutocompleteQuery(
}, },
select: React.useCallback( select: React.useCallback(
(data: AppBskyActorDefs.ProfileViewBasic[]) => { (data: AppBskyActorDefs.ProfileViewBasic[]) => {
return computeSuggestions(data, moderationOpts || DEFAULT_MOD_OPTS) return computeSuggestions({
q: prefix,
searched: data,
moderationOpts: moderationOpts || DEFAULT_MOD_OPTS,
})
}, },
[moderationOpts], [prefix, moderationOpts],
), ),
placeholderData: maintainData ? keepPreviousData : undefined, placeholderData: maintainData ? keepPreviousData : undefined,
}) })
@ -81,19 +85,25 @@ export function useActorAutocompleteFn() {
} }
} }
return computeSuggestions( return computeSuggestions({
res?.data.actors, q: query,
moderationOpts || DEFAULT_MOD_OPTS, searched: res?.data.actors,
) moderationOpts: moderationOpts || DEFAULT_MOD_OPTS,
})
}, },
[queryClient, moderationOpts, agent], [queryClient, moderationOpts, agent],
) )
} }
function computeSuggestions( function computeSuggestions({
searched: AppBskyActorDefs.ProfileViewBasic[] = [], q,
moderationOpts: ModerationOpts, searched = [],
) { moderationOpts,
}: {
q?: string
searched?: AppBskyActorDefs.ProfileViewBasic[]
moderationOpts: ModerationOpts
}) {
let items: AppBskyActorDefs.ProfileViewBasic[] = [] let items: AppBskyActorDefs.ProfileViewBasic[] = []
for (const item of searched) { for (const item of searched) {
if (!items.find(item2 => item2.handle === item.handle)) { if (!items.find(item2 => item2.handle === item.handle)) {
@ -102,6 +112,7 @@ function computeSuggestions(
} }
return items.filter(profile => { return items.filter(profile => {
const modui = moderateProfile(profile, moderationOpts).ui('profileList') const modui = moderateProfile(profile, moderationOpts).ui('profileList')
return !modui.filter || isJustAMute(modui) const isExactMatch = q && profile.handle.toLowerCase() === q
return isExactMatch || !modui.filter || isJustAMute(modui)
}) })
} }