Search - extra tabs (#3408)
* add extra tab to search and translate tab names
* add feature gate
* flatten pager children
* Revert "flatten pager children"
This reverts commit 0050d42558.
* have pager children as array
* move gate to custom hook
* bundle titles and pages together
* remove comment
* Fix a crash
* Use Views as children
---------
Co-authored-by: dan <dan.abramov@gmail.com>
This commit is contained in:
@@ -10,12 +10,19 @@ import {getAgent} from '#/state/session'
|
||||
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
||||
|
||||
const searchPostsQueryKeyRoot = 'search-posts'
|
||||
const searchPostsQueryKey = ({query}: {query: string}) => [
|
||||
const searchPostsQueryKey = ({query, sort}: {query: string; sort?: string}) => [
|
||||
searchPostsQueryKeyRoot,
|
||||
query,
|
||||
sort,
|
||||
]
|
||||
|
||||
export function useSearchPostsQuery({query}: {query: string}) {
|
||||
export function useSearchPostsQuery({
|
||||
query,
|
||||
sort,
|
||||
}: {
|
||||
query: string
|
||||
sort?: 'top' | 'latest'
|
||||
}) {
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedSearchPosts.OutputSchema,
|
||||
Error,
|
||||
@@ -23,14 +30,20 @@ export function useSearchPostsQuery({query}: {query: string}) {
|
||||
QueryKey,
|
||||
string | undefined
|
||||
>({
|
||||
queryKey: searchPostsQueryKey({query}),
|
||||
queryKey: searchPostsQueryKey({query, sort}),
|
||||
queryFn: async ({pageParam}) => {
|
||||
const res = await getAgent().app.bsky.feed.searchPosts({
|
||||
q: query,
|
||||
limit: 25,
|
||||
cursor: pageParam,
|
||||
})
|
||||
return res.data
|
||||
// waiting on new APIs
|
||||
switch (sort) {
|
||||
// case 'top':
|
||||
// case 'latest':
|
||||
default:
|
||||
const res = await getAgent().app.bsky.feed.searchPosts({
|
||||
q: query,
|
||||
limit: 25,
|
||||
cursor: pageParam,
|
||||
})
|
||||
return res.data
|
||||
}
|
||||
},
|
||||
initialPageParam: undefined,
|
||||
getNextPageParam: lastPage => lastPage.cursor,
|
||||
|
||||
Reference in New Issue
Block a user