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(
(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,
})
@ -81,19 +85,25 @@ export function useActorAutocompleteFn() {
}
}
return computeSuggestions(
res?.data.actors,
moderationOpts || DEFAULT_MOD_OPTS,
)
return computeSuggestions({
q: query,
searched: res?.data.actors,
moderationOpts: moderationOpts || DEFAULT_MOD_OPTS,
})
},
[queryClient, moderationOpts, agent],
)
}
function computeSuggestions(
searched: AppBskyActorDefs.ProfileViewBasic[] = [],
moderationOpts: ModerationOpts,
) {
function computeSuggestions({
q,
searched = [],
moderationOpts,
}: {
q?: string
searched?: AppBskyActorDefs.ProfileViewBasic[]
moderationOpts: ModerationOpts
}) {
let items: AppBskyActorDefs.ProfileViewBasic[] = []
for (const item of searched) {
if (!items.find(item2 => item2.handle === item.handle)) {
@ -102,6 +112,7 @@ function computeSuggestions(
}
return items.filter(profile => {
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)
})
}