No need to await follows anymore, fix cold load search (#1918)
parent
fe1a7183fc
commit
9bcd00b831
|
@ -33,7 +33,6 @@ import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
import {usePalette} from '#/lib/hooks/usePalette'
|
import {usePalette} from '#/lib/hooks/usePalette'
|
||||||
import {useTheme} from 'lib/ThemeContext'
|
import {useTheme} from 'lib/ThemeContext'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
import {useMyFollowsQuery} from '#/state/queries/my-follows'
|
|
||||||
import {useGetSuggestedFollowersByActor} from '#/state/queries/suggested-follows'
|
import {useGetSuggestedFollowersByActor} from '#/state/queries/suggested-follows'
|
||||||
import {useSearchPostsQuery} from '#/state/queries/search-posts'
|
import {useSearchPostsQuery} from '#/state/queries/search-posts'
|
||||||
import {useActorAutocompleteFn} from '#/state/queries/actor-autocomplete'
|
import {useActorAutocompleteFn} from '#/state/queries/actor-autocomplete'
|
||||||
|
@ -298,8 +297,6 @@ function SearchScreenUserResults({query}: {query: string}) {
|
||||||
AppBskyActorDefs.ProfileViewBasic[]
|
AppBskyActorDefs.ProfileViewBasic[]
|
||||||
>([])
|
>([])
|
||||||
const search = useActorAutocompleteFn()
|
const search = useActorAutocompleteFn()
|
||||||
// fuzzy search relies on followers
|
|
||||||
const {isFetched: isFollowsFetched} = useMyFollowsQuery()
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
async function getResults() {
|
async function getResults() {
|
||||||
|
@ -312,13 +309,13 @@ function SearchScreenUserResults({query}: {query: string}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query && isFollowsFetched) {
|
if (query) {
|
||||||
getResults()
|
getResults()
|
||||||
} else {
|
} else {
|
||||||
setResults([])
|
setResults([])
|
||||||
setIsFetched(false)
|
setIsFetched(false)
|
||||||
}
|
}
|
||||||
}, [query, isFollowsFetched, setDataUpdatedAt, search])
|
}, [query, setDataUpdatedAt, search])
|
||||||
|
|
||||||
return isFetched ? (
|
return isFetched ? (
|
||||||
<>
|
<>
|
||||||
|
@ -413,7 +410,7 @@ export function SearchScreenDesktop(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SearchScreenMobile(
|
export function SearchScreenMobile(
|
||||||
_props: NativeStackScreenProps<SearchTabNavigatorParams, 'Search'>,
|
props: NativeStackScreenProps<SearchTabNavigatorParams, 'Search'>,
|
||||||
) {
|
) {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const textInput = React.useRef<TextInput>(null)
|
const textInput = React.useRef<TextInput>(null)
|
||||||
|
@ -431,7 +428,7 @@ export function SearchScreenMobile(
|
||||||
undefined,
|
undefined,
|
||||||
)
|
)
|
||||||
const [isFetching, setIsFetching] = React.useState<boolean>(false)
|
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<
|
const [searchResults, setSearchResults] = React.useState<
|
||||||
AppBskyActorDefs.ProfileViewBasic[]
|
AppBskyActorDefs.ProfileViewBasic[]
|
||||||
>([])
|
>([])
|
||||||
|
|
Loading…
Reference in New Issue