Skip to content

Commit

Permalink
Search page (#1912)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
estrattonbailey and pfrazee authored Nov 15, 2023
1 parent d5ea319 commit 22b7642
Show file tree
Hide file tree
Showing 14 changed files with 742 additions and 991 deletions.
69 changes: 0 additions & 69 deletions src/state/models/ui/search.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/state/queries/actor-autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function useActorAutocompleteFn() {
const {data: follows} = useMyFollowsQuery()

return React.useCallback(
async ({query}: {query: string}) => {
async ({query, limit = 8}: {query: string; limit?: number}) => {
let res
if (query) {
try {
Expand All @@ -47,7 +47,7 @@ export function useActorAutocompleteFn() {
queryFn: () =>
agent.searchActorsTypeahead({
term: query,
limit: 8,
limit,
}),
})
} catch (e) {
Expand Down
32 changes: 32 additions & 0 deletions src/state/queries/search-posts.ts
Original file line number Diff line number Diff line change
@@ -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,
})
}
30 changes: 20 additions & 10 deletions src/state/queries/suggested-follows.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react'
import {
AppBskyActorGetSuggestions,
AppBskyGraphGetSuggestedFollowsByActor,
moderateProfile,
} from '@atproto/api'
import {
useInfiniteQuery,
useMutation,
useQueryClient,
useQuery,
InfiniteData,
QueryKey,
Expand All @@ -15,7 +16,7 @@ import {useSession} from '#/state/session'
import {useModerationOpts} from '#/state/queries/preferences'

const suggestedFollowsQueryKey = ['suggested-follows']
const suggestedFollowsByActorQuery = (did: string) => [
const suggestedFollowsByActorQueryKey = (did: string) => [
'suggested-follows-by-actor',
did,
]
Expand Down Expand Up @@ -73,7 +74,7 @@ export function useSuggestedFollowsByActorQuery({did}: {did: string}) {
const {agent} = useSession()

return useQuery<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema, Error>({
queryKey: suggestedFollowsByActorQuery(did),
queryKey: suggestedFollowsByActorQueryKey(did),
queryFn: async () => {
const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({
actor: did,
Expand All @@ -83,17 +84,26 @@ export function useSuggestedFollowsByActorQuery({did}: {did: string}) {
})
}

// TODO: Delete and replace usages with the one above.
// TODO refactor onboarding to use above, but this is still used
export function useGetSuggestedFollowersByActor() {
const {agent} = useSession()
const queryClient = useQueryClient()

return useMutation({
mutationFn: async (actor: string) => {
const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({
actor: actor,
return React.useCallback(
async (actor: string) => {
const res = await queryClient.fetchQuery({
staleTime: 60 * 1000,
queryKey: suggestedFollowsByActorQueryKey(actor),
queryFn: async () => {
const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({
actor: actor,
})
return res.data
},
})

return res.data
return res
},
})
[agent, queryClient],
)
}
186 changes: 0 additions & 186 deletions src/view/com/search/HeaderWithInput.tsx

This file was deleted.

Loading

0 comments on commit 22b7642

Please sign in to comment.