diff --git a/src/lib/statsig/gates.ts b/src/lib/statsig/gates.ts new file mode 100644 index 0000000000..fce25cb887 --- /dev/null +++ b/src/lib/statsig/gates.ts @@ -0,0 +1,3 @@ +import {useGate} from './statsig' + +export const useNewSearchGate = () => useGate('new_search') diff --git a/src/state/queries/search-posts.ts b/src/state/queries/search-posts.ts index 9bf3c0f9ec..ef8b083584 100644 --- a/src/state/queries/search-posts.ts +++ b/src/state/queries/search-posts.ts @@ -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, diff --git a/src/view/screens/Search/Search.tsx b/src/view/screens/Search/Search.tsx index c0f4cf1950..fe7a52234b 100644 --- a/src/view/screens/Search/Search.tsx +++ b/src/view/screens/Search/Search.tsx @@ -22,6 +22,7 @@ import {HITSLOP_10} from '#/lib/constants' import {usePalette} from '#/lib/hooks/usePalette' import {MagnifyingGlassIcon} from '#/lib/icons' import {NavigationProp} from '#/lib/routes/types' +import {useNewSearchGate} from '#/lib/statsig/gates' import {augmentSearchQuery} from '#/lib/strings/helpers' import {s} from '#/lib/styles' import {logger} from '#/logger' @@ -191,7 +192,13 @@ type SearchResultSlice = key: string } -function SearchScreenPostResults({query}: {query: string}) { +function SearchScreenPostResults({ + query, + sort, +}: { + query: string + sort?: 'top' | 'latest' +}) { const {_} = useLingui() const {currentAccount} = useSession() const [isPTR, setIsPTR] = React.useState(false) @@ -209,7 +216,7 @@ function SearchScreenPostResults({query}: {query: string}) { fetchNextPage, isFetchingNextPage, hasNextPage, - } = useSearchPostsQuery({query: augmentedQuery}) + } = useSearchPostsQuery({query: augmentedQuery, sort}) const onPullToRefresh = React.useCallback(async () => { setIsPTR(true) @@ -316,8 +323,6 @@ function SearchScreenUserResults({query}: {query: string}) { ) } -const SECTIONS_LOGGEDOUT = ['Users'] -const SECTIONS_LOGGEDIN = ['Posts', 'Users'] export function SearchScreenInner({ query, primarySearch, @@ -330,6 +335,9 @@ export function SearchScreenInner({ const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled() const {hasSession} = useSession() const {isDesktop} = useWebMediaQueries() + const {_} = useLingui() + + const isNewSearch = useNewSearchGate() const onPageSelected = React.useCallback( (index: number) => { @@ -339,6 +347,55 @@ export function SearchScreenInner({ [setDrawerSwipeDisabled, setMinimalShellMode], ) + const sections = React.useMemo(() => { + if (!query) return [] + if (isNewSearch) { + if (hasSession) { + return [ + { + title: _(msg`Top`), + component: , + }, + { + title: _(msg`Latest`), + component: , + }, + { + title: _(msg`People`), + component: , + }, + ] + } else { + return [ + { + title: _(msg`People`), + component: , + }, + ] + } + } else { + if (hasSession) { + return [ + { + title: _(msg`Posts`), + component: , + }, + { + title: _(msg`Users`), + component: , + }, + ] + } else { + return [ + { + title: _(msg`Users`), + component: , + }, + ] + } + } + }, [hasSession, isNewSearch, _, query]) + if (hasSession) { return query ? ( - + section.title)} {...props} /> )} initialPage={0}> - - - - - - + {sections.map((section, i) => ( + {section.component} + ))} ) : ( @@ -389,13 +443,13 @@ export function SearchScreenInner({ - + section.title)} {...props} /> )} initialPage={0}> - - - + {sections.map((section, i) => ( + {section.component} + ))} ) : (