add extra tab to search and translate tab names
This commit is contained in:
@@ -10,12 +10,19 @@ import {getAgent} from '#/state/session'
|
|||||||
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
||||||
|
|
||||||
const searchPostsQueryKeyRoot = 'search-posts'
|
const searchPostsQueryKeyRoot = 'search-posts'
|
||||||
const searchPostsQueryKey = ({query}: {query: string}) => [
|
const searchPostsQueryKey = ({query, sort}: {query: string; sort?: string}) => [
|
||||||
searchPostsQueryKeyRoot,
|
searchPostsQueryKeyRoot,
|
||||||
query,
|
query,
|
||||||
|
sort,
|
||||||
]
|
]
|
||||||
|
|
||||||
export function useSearchPostsQuery({query}: {query: string}) {
|
export function useSearchPostsQuery({
|
||||||
|
query,
|
||||||
|
sort,
|
||||||
|
}: {
|
||||||
|
query: string
|
||||||
|
sort?: 'top' | 'latest'
|
||||||
|
}) {
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyFeedSearchPosts.OutputSchema,
|
AppBskyFeedSearchPosts.OutputSchema,
|
||||||
Error,
|
Error,
|
||||||
@@ -23,14 +30,20 @@ export function useSearchPostsQuery({query}: {query: string}) {
|
|||||||
QueryKey,
|
QueryKey,
|
||||||
string | undefined
|
string | undefined
|
||||||
>({
|
>({
|
||||||
queryKey: searchPostsQueryKey({query}),
|
queryKey: searchPostsQueryKey({query, sort}),
|
||||||
queryFn: async ({pageParam}) => {
|
queryFn: async ({pageParam}) => {
|
||||||
const res = await getAgent().app.bsky.feed.searchPosts({
|
// waiting on new APIs
|
||||||
q: query,
|
switch (sort) {
|
||||||
limit: 25,
|
// case 'top':
|
||||||
cursor: pageParam,
|
// case 'latest':
|
||||||
})
|
default:
|
||||||
return res.data
|
const res = await getAgent().app.bsky.feed.searchPosts({
|
||||||
|
q: query,
|
||||||
|
limit: 25,
|
||||||
|
cursor: pageParam,
|
||||||
|
})
|
||||||
|
return res.data
|
||||||
|
}
|
||||||
},
|
},
|
||||||
initialPageParam: undefined,
|
initialPageParam: undefined,
|
||||||
getNextPageParam: lastPage => lastPage.cursor,
|
getNextPageParam: lastPage => lastPage.cursor,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
FontAwesomeIcon,
|
FontAwesomeIcon,
|
||||||
FontAwesomeIconStyle,
|
FontAwesomeIconStyle,
|
||||||
} from '@fortawesome/react-native-fontawesome'
|
} from '@fortawesome/react-native-fontawesome'
|
||||||
|
import {type I18n} from '@lingui/core'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||||
@@ -191,7 +192,13 @@ type SearchResultSlice =
|
|||||||
key: string
|
key: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function SearchScreenPostResults({query}: {query: string}) {
|
function SearchScreenPostResults({
|
||||||
|
query,
|
||||||
|
sort,
|
||||||
|
}: {
|
||||||
|
query: string
|
||||||
|
sort: 'top' | 'latest'
|
||||||
|
}) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const [isPTR, setIsPTR] = React.useState(false)
|
const [isPTR, setIsPTR] = React.useState(false)
|
||||||
@@ -209,7 +216,7 @@ function SearchScreenPostResults({query}: {query: string}) {
|
|||||||
fetchNextPage,
|
fetchNextPage,
|
||||||
isFetchingNextPage,
|
isFetchingNextPage,
|
||||||
hasNextPage,
|
hasNextPage,
|
||||||
} = useSearchPostsQuery({query: augmentedQuery})
|
} = useSearchPostsQuery({query: augmentedQuery, sort})
|
||||||
|
|
||||||
const onPullToRefresh = React.useCallback(async () => {
|
const onPullToRefresh = React.useCallback(async () => {
|
||||||
setIsPTR(true)
|
setIsPTR(true)
|
||||||
@@ -316,8 +323,25 @@ function SearchScreenUserResults({query}: {query: string}) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const SECTIONS_LOGGEDOUT = ['Users']
|
const SECTIONS_LOGGEDOUT = ['PEOPLE'] as const
|
||||||
const SECTIONS_LOGGEDIN = ['Posts', 'Users']
|
const SECTIONS_LOGGEDIN = ['TOP', 'LATEST', 'PEOPLE'] as const
|
||||||
|
|
||||||
|
function getSectionName(
|
||||||
|
i18n: I18n,
|
||||||
|
section:
|
||||||
|
| (typeof SECTIONS_LOGGEDIN)[number]
|
||||||
|
| (typeof SECTIONS_LOGGEDOUT)[number],
|
||||||
|
) {
|
||||||
|
switch (section) {
|
||||||
|
case 'TOP':
|
||||||
|
return i18n._(msg`Top`)
|
||||||
|
case 'LATEST':
|
||||||
|
return i18n._(msg`Latest`)
|
||||||
|
case 'PEOPLE':
|
||||||
|
return i18n._(msg`People`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function SearchScreenInner({
|
export function SearchScreenInner({
|
||||||
query,
|
query,
|
||||||
primarySearch,
|
primarySearch,
|
||||||
@@ -330,6 +354,7 @@ export function SearchScreenInner({
|
|||||||
const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled()
|
const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled()
|
||||||
const {hasSession} = useSession()
|
const {hasSession} = useSession()
|
||||||
const {isDesktop} = useWebMediaQueries()
|
const {isDesktop} = useWebMediaQueries()
|
||||||
|
const {i18n} = useLingui()
|
||||||
|
|
||||||
const onPageSelected = React.useCallback(
|
const onPageSelected = React.useCallback(
|
||||||
(index: number) => {
|
(index: number) => {
|
||||||
@@ -339,6 +364,13 @@ export function SearchScreenInner({
|
|||||||
[setDrawerSwipeDisabled, setMinimalShellMode],
|
[setDrawerSwipeDisabled, setMinimalShellMode],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const sections = hasSession ? SECTIONS_LOGGEDIN : SECTIONS_LOGGEDOUT
|
||||||
|
|
||||||
|
const tabBarItems = React.useMemo(
|
||||||
|
() => sections.map(section => getSectionName(i18n, section)),
|
||||||
|
[sections, i18n],
|
||||||
|
)
|
||||||
|
|
||||||
if (hasSession) {
|
if (hasSession) {
|
||||||
return query ? (
|
return query ? (
|
||||||
<Pager
|
<Pager
|
||||||
@@ -347,12 +379,15 @@ export function SearchScreenInner({
|
|||||||
<CenteredView
|
<CenteredView
|
||||||
sideBorders
|
sideBorders
|
||||||
style={[pal.border, pal.view, styles.tabBarContainer]}>
|
style={[pal.border, pal.view, styles.tabBarContainer]}>
|
||||||
<TabBar items={SECTIONS_LOGGEDIN} {...props} />
|
<TabBar items={tabBarItems} {...props} />
|
||||||
</CenteredView>
|
</CenteredView>
|
||||||
)}
|
)}
|
||||||
initialPage={0}>
|
initialPage={0}>
|
||||||
<View>
|
<View>
|
||||||
<SearchScreenPostResults query={query} />
|
<SearchScreenPostResults query={query} sort="top" />
|
||||||
|
</View>
|
||||||
|
<View>
|
||||||
|
<SearchScreenPostResults query={query} sort="latest" />
|
||||||
</View>
|
</View>
|
||||||
<View>
|
<View>
|
||||||
<SearchScreenUserResults query={query} />
|
<SearchScreenUserResults query={query} />
|
||||||
@@ -389,7 +424,7 @@ export function SearchScreenInner({
|
|||||||
<CenteredView
|
<CenteredView
|
||||||
sideBorders
|
sideBorders
|
||||||
style={[pal.border, pal.view, styles.tabBarContainer]}>
|
style={[pal.border, pal.view, styles.tabBarContainer]}>
|
||||||
<TabBar items={SECTIONS_LOGGEDOUT} {...props} />
|
<TabBar items={tabBarItems} {...props} />
|
||||||
</CenteredView>
|
</CenteredView>
|
||||||
)}
|
)}
|
||||||
initialPage={0}>
|
initialPage={0}>
|
||||||
|
|||||||
Reference in New Issue
Block a user