No need to await follows anymore, fix cold load search (#1918)

zio/stable
Eric Bailey 2023-11-15 19:08:08 -06:00 committed by GitHub
parent fe1a7183fc
commit 9bcd00b831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 7 deletions

View File

@ -33,7 +33,6 @@ import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {usePalette} from '#/lib/hooks/usePalette'
import {useTheme} from 'lib/ThemeContext'
import {useSession} from '#/state/session'
import {useMyFollowsQuery} from '#/state/queries/my-follows'
import {useGetSuggestedFollowersByActor} from '#/state/queries/suggested-follows'
import {useSearchPostsQuery} from '#/state/queries/search-posts'
import {useActorAutocompleteFn} from '#/state/queries/actor-autocomplete'
@ -298,8 +297,6 @@ function SearchScreenUserResults({query}: {query: string}) {
AppBskyActorDefs.ProfileViewBasic[]
>([])
const search = useActorAutocompleteFn()
// fuzzy search relies on followers
const {isFetched: isFollowsFetched} = useMyFollowsQuery()
React.useEffect(() => {
async function getResults() {
@ -312,13 +309,13 @@ function SearchScreenUserResults({query}: {query: string}) {
}
}
if (query && isFollowsFetched) {
if (query) {
getResults()
} else {
setResults([])
setIsFetched(false)
}
}, [query, isFollowsFetched, setDataUpdatedAt, search])
}, [query, setDataUpdatedAt, search])
return isFetched ? (
<>
@ -413,7 +410,7 @@ export function SearchScreenDesktop(
}
export function SearchScreenMobile(
_props: NativeStackScreenProps<SearchTabNavigatorParams, 'Search'>,
props: NativeStackScreenProps<SearchTabNavigatorParams, 'Search'>,
) {
const theme = useTheme()
const textInput = React.useRef<TextInput>(null)
@ -431,7 +428,7 @@ export function SearchScreenMobile(
undefined,
)
const [isFetching, setIsFetching] = React.useState<boolean>(false)
const [query, setQuery] = React.useState<string>('')
const [query, setQuery] = React.useState<string>(props.route?.params?.q || '')
const [searchResults, setSearchResults] = React.useState<
AppBskyActorDefs.ProfileViewBasic[]
>([])