use top search results
This commit is contained in:
@@ -4,8 +4,7 @@ import {KeyboardAwareScrollView} from 'react-native-keyboard-controller'
|
|||||||
import {AppBskyActorDefs} from '@atproto/api'
|
import {AppBskyActorDefs} from '@atproto/api'
|
||||||
|
|
||||||
import {useActorAutocompleteQuery} from 'state/queries/actor-autocomplete'
|
import {useActorAutocompleteQuery} from 'state/queries/actor-autocomplete'
|
||||||
import {useProfileFollowsQuery} from 'state/queries/profile-follows'
|
import {useActorSearch} from 'state/queries/actor-search'
|
||||||
import {useSession} from 'state/session'
|
|
||||||
import {SearchInput} from 'view/com/util/forms/SearchInput'
|
import {SearchInput} from 'view/com/util/forms/SearchInput'
|
||||||
import {List} from 'view/com/util/List'
|
import {List} from 'view/com/util/List'
|
||||||
import {useWizardState} from '#/screens/StarterPack/Wizard/State'
|
import {useWizardState} from '#/screens/StarterPack/Wizard/State'
|
||||||
@@ -23,17 +22,11 @@ export function StepProfiles() {
|
|||||||
const [state, dispatch] = useWizardState()
|
const [state, dispatch] = useWizardState()
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState('')
|
||||||
|
|
||||||
const {currentAccount} = useSession()
|
const {data: topFollowers} = useActorSearch({
|
||||||
const {data: followsPages, fetchNextPage} = useProfileFollowsQuery(
|
query: encodeURIComponent('*'),
|
||||||
currentAccount?.did,
|
limit: 50,
|
||||||
)
|
})
|
||||||
const follows = followsPages?.pages.flatMap(page => page.follows) || []
|
const {data: results} = useActorAutocompleteQuery(query, true, 12)
|
||||||
|
|
||||||
const {data: results} = useActorAutocompleteQuery(
|
|
||||||
query || encodeURIComponent('*'),
|
|
||||||
true,
|
|
||||||
12,
|
|
||||||
)
|
|
||||||
|
|
||||||
const renderItem = ({
|
const renderItem = ({
|
||||||
item,
|
item,
|
||||||
@@ -56,12 +49,10 @@ export function StepProfiles() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<List
|
<List
|
||||||
data={query ? results : follows}
|
data={query ? results : topFollowers}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
keyExtractor={keyExtractor}
|
keyExtractor={keyExtractor}
|
||||||
contentContainerStyle={{paddingTop: 12}}
|
contentContainerStyle={{paddingTop: 12}}
|
||||||
onEndReached={!query ? () => fetchNextPage() : undefined}
|
|
||||||
onEndReachedThreshold={2}
|
|
||||||
renderScrollComponent={props => <KeyboardAwareScrollView {...props} />}
|
renderScrollComponent={props => <KeyboardAwareScrollView {...props} />}
|
||||||
keyboardShouldPersistTaps="handled"
|
keyboardShouldPersistTaps="handled"
|
||||||
containWeb={true}
|
containWeb={true}
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ export const RQKEY = (query: string) => [RQKEY_ROOT, query]
|
|||||||
|
|
||||||
export function useActorSearch({
|
export function useActorSearch({
|
||||||
query,
|
query,
|
||||||
|
limit = 20,
|
||||||
enabled,
|
enabled,
|
||||||
}: {
|
}: {
|
||||||
query: string
|
query: string
|
||||||
|
limit?: number
|
||||||
enabled?: boolean
|
enabled?: boolean
|
||||||
}) {
|
}) {
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
@@ -21,6 +23,7 @@ export function useActorSearch({
|
|||||||
async queryFn() {
|
async queryFn() {
|
||||||
const res = await agent.searchActors({
|
const res = await agent.searchActors({
|
||||||
q: query,
|
q: query,
|
||||||
|
limit,
|
||||||
})
|
})
|
||||||
return res.data.actors
|
return res.data.actors
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user