diff options
author | Eric Bailey <git@esb.lol> | 2023-11-15 17:55:28 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 15:55:28 -0800 |
commit | 22b76423a0a0e5cfb40bb00c22dec628f5a5a4c0 (patch) | |
tree | 6aa44409fa109d17f9e9f97b6f12aa51a6507ffb /src/state/queries/search-posts.ts | |
parent | d5ea31920caa2eade6015ad59122f06a8b280ab9 (diff) | |
download | voidsky-22b76423a0a0e5cfb40bb00c22dec628f5a5a4c0.tar.zst |
Search page (#1912)
* Desktop web work * Mobile search * Dedupe suggestions * Clean up and reorg * Cleanup * Cleanup * Use Pager * Delete unused code * Fix conflicts * Remove search ui model * Soft reset * Fix scrollable results, remove observer * Use correct ScrollView * Clean up layout --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/state/queries/search-posts.ts')
-rw-r--r-- | src/state/queries/search-posts.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/state/queries/search-posts.ts b/src/state/queries/search-posts.ts new file mode 100644 index 000000000..ab6ed4d41 --- /dev/null +++ b/src/state/queries/search-posts.ts @@ -0,0 +1,32 @@ +import {AppBskyFeedSearchPosts} from '@atproto/api' +import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' + +import {useSession} from '#/state/session' + +const searchPostsQueryKey = ({query}: {query: string}) => [ + 'search-posts', + query, +] + +export function useSearchPostsQuery({query}: {query: string}) { + const {agent} = useSession() + + return useInfiniteQuery< + AppBskyFeedSearchPosts.OutputSchema, + Error, + InfiniteData<AppBskyFeedSearchPosts.OutputSchema>, + QueryKey, + string | undefined + >({ + queryKey: searchPostsQueryKey({query}), + queryFn: async () => { + const res = await agent.app.bsky.feed.searchPosts({ + q: query, + limit: 25, + }) + return res.data + }, + initialPageParam: undefined, + getNextPageParam: lastPage => lastPage.cursor, + }) +} |