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
42
src/state/queries/actor-search.ts
Normal file
42
src/state/queries/actor-search.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import {AppBskyActorDefs} from '@atproto/api'
|
||||
import {QueryClient, useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
export const RQKEY = (prefix: string) => ['actor-search', prefix]
|
||||
|
||||
export function useActorSearch(prefix: string) {
|
||||
return useQuery<AppBskyActorDefs.ProfileView[]>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(prefix || ''),
|
||||
async queryFn() {
|
||||
const res = await getAgent().searchActors({
|
||||
term: prefix,
|
||||
})
|
||||
return res.data.actors
|
||||
},
|
||||
enabled: !!prefix,
|
||||
})
|
||||
}
|
||||
|
||||
export function* findAllProfilesInQueryData(
|
||||
queryClient: QueryClient,
|
||||
did: string,
|
||||
) {
|
||||
const queryDatas = queryClient.getQueriesData<AppBskyActorDefs.ProfileView[]>(
|
||||
{
|
||||
queryKey: ['actor-search'],
|
||||
},
|
||||
)
|
||||
for (const [_queryKey, queryData] of queryDatas) {
|
||||
if (!queryData) {
|
||||
continue
|
||||
}
|
||||
for (const actor of queryData) {
|
||||
if (actor.did === did) {
|
||||
yield actor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue