Various search fixes (#2145)
* Add posts-search query to shadow cache search * Update user search to use correct endpoint * Fix: include cursor in post search
This commit is contained in:
parent
448a403c81
commit
7b50331188
5 changed files with 88 additions and 34 deletions
|
@ -36,6 +36,7 @@ import {useTheme} from 'lib/ThemeContext'
|
|||
import {useSession} from '#/state/session'
|
||||
import {useGetSuggestedFollowersByActor} from '#/state/queries/suggested-follows'
|
||||
import {useSearchPostsQuery} from '#/state/queries/search-posts'
|
||||
import {useActorSearch} from '#/state/queries/actor-search'
|
||||
import {useActorAutocompleteFn} from '#/state/queries/actor-autocomplete'
|
||||
import {useSetDrawerOpen} from '#/state/shell'
|
||||
import {useAnalytics} from '#/lib/analytics/analytics'
|
||||
|
@ -278,38 +279,9 @@ function SearchScreenPostResults({query}: {query: string}) {
|
|||
|
||||
function SearchScreenUserResults({query}: {query: string}) {
|
||||
const {_} = useLingui()
|
||||
const [isFetched, setIsFetched] = React.useState(false)
|
||||
const [results, setResults] = React.useState<
|
||||
AppBskyActorDefs.ProfileViewBasic[]
|
||||
>([])
|
||||
const search = useActorAutocompleteFn()
|
||||
const {data: results, isFetched} = useActorSearch(query)
|
||||
|
||||
React.useEffect(() => {
|
||||
async function getResults() {
|
||||
try {
|
||||
const searchResults = await search({query, limit: 30})
|
||||
|
||||
if (searchResults) {
|
||||
setResults(searchResults)
|
||||
}
|
||||
} catch (e: any) {
|
||||
logger.error(`SearchScreenUserResults: failed to get results`, {
|
||||
error: e.toString(),
|
||||
})
|
||||
} finally {
|
||||
setIsFetched(true)
|
||||
}
|
||||
}
|
||||
|
||||
if (query) {
|
||||
getResults()
|
||||
} else {
|
||||
setResults([])
|
||||
setIsFetched(false)
|
||||
}
|
||||
}, [query, search, setResults])
|
||||
|
||||
return isFetched ? (
|
||||
return isFetched && results ? (
|
||||
<>
|
||||
{results.length ? (
|
||||
<FlatList
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue