Migrate all search to v2 and remove v1 (#11125)
This commit is contained in:
+25
-24
@@ -1,9 +1,7 @@
|
||||
import {useCallback, useMemo, useState} from 'react'
|
||||
import {type ListRenderItemInfo, View} from 'react-native'
|
||||
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {type NativeStackScreenProps} from '@react-navigation/native-stack'
|
||||
|
||||
import {HITSLOP_10} from '#/lib/constants'
|
||||
@@ -14,7 +12,7 @@ import {shareUrl} from '#/lib/sharing'
|
||||
import {cleanError} from '#/lib/strings/errors'
|
||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||
import {enforceLen} from '#/lib/strings/helpers'
|
||||
import {useSearchPostsQuery} from '#/state/queries/search-posts'
|
||||
import {useSearchPostsV2Query} from '#/state/queries/search-posts-v2'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||
import {useCloseAllActiveElements} from '#/state/util'
|
||||
@@ -43,7 +41,7 @@ export default function HashtagScreen({
|
||||
route,
|
||||
}: NativeStackScreenProps<CommonNavigatorParams, 'Hashtag'>) {
|
||||
const {tag, author} = route.params
|
||||
const {_} = useLingui()
|
||||
const {t: l} = useLingui()
|
||||
|
||||
const decodedTag = useMemo(() => {
|
||||
return decodeURIComponent(tag)
|
||||
@@ -73,7 +71,7 @@ export default function HashtagScreen({
|
||||
if (author) {
|
||||
url.searchParams.set('author', author)
|
||||
}
|
||||
shareUrl(url.toString())
|
||||
void shareUrl(url.toString())
|
||||
}, [tag, author])
|
||||
|
||||
const [activeTab, setActiveTab] = useState(0)
|
||||
@@ -85,7 +83,7 @@ export default function HashtagScreen({
|
||||
const sections = useMemo(() => {
|
||||
return [
|
||||
{
|
||||
title: _(msg`Top`),
|
||||
title: l`Top`,
|
||||
component: (
|
||||
<HashtagScreenTab
|
||||
fullTag={fullTag}
|
||||
@@ -96,7 +94,7 @@ export default function HashtagScreen({
|
||||
),
|
||||
},
|
||||
{
|
||||
title: _(msg`Latest`),
|
||||
title: l`Latest`,
|
||||
component: (
|
||||
<HashtagScreenTab
|
||||
fullTag={fullTag}
|
||||
@@ -107,7 +105,7 @@ export default function HashtagScreen({
|
||||
),
|
||||
},
|
||||
]
|
||||
}, [_, fullTag, author, activeTab])
|
||||
}, [l, fullTag, author, activeTab])
|
||||
|
||||
return (
|
||||
<Layout.Screen>
|
||||
@@ -122,14 +120,14 @@ export default function HashtagScreen({
|
||||
{author && (
|
||||
<Layout.Header.SubtitleText>
|
||||
{author.startsWith('did:')
|
||||
? _(msg`From ${sanitizedAuthor}`)
|
||||
: _(msg`From @${sanitizedAuthor}`)}
|
||||
? l`From ${sanitizedAuthor}`
|
||||
: l`From @${sanitizedAuthor}`}
|
||||
</Layout.Header.SubtitleText>
|
||||
)}
|
||||
</Layout.Header.Content>
|
||||
<Layout.Header.Slot>
|
||||
<Button
|
||||
label={_(msg`Share`)}
|
||||
label={l`Share`}
|
||||
size="small"
|
||||
variant="ghost"
|
||||
color="primary"
|
||||
@@ -164,7 +162,7 @@ function HashtagScreenTab({
|
||||
sort: 'top' | 'latest'
|
||||
active: boolean
|
||||
}) {
|
||||
const {_} = useLingui()
|
||||
const {t: l} = useLingui()
|
||||
const initialNumToRender = useInitialNumToRender()
|
||||
const [isPTR, setIsPTR] = useState(false)
|
||||
const t = useTheme()
|
||||
@@ -188,7 +186,14 @@ function HashtagScreenTab({
|
||||
refetch,
|
||||
fetchNextPage,
|
||||
hasNextPage,
|
||||
} = useSearchPostsQuery({query: queryParam, sort, enabled: active, author})
|
||||
} = useSearchPostsV2Query({
|
||||
query: queryParam,
|
||||
sort,
|
||||
enabled: active,
|
||||
filters: {
|
||||
author,
|
||||
},
|
||||
})
|
||||
|
||||
const posts = useMemo(() => {
|
||||
return data?.pages.flatMap(page => page.posts) || []
|
||||
@@ -202,7 +207,7 @@ function HashtagScreenTab({
|
||||
|
||||
const onEndReached = useCallback(() => {
|
||||
if (isFetchingNextPage || !hasNextPage || error) return
|
||||
fetchNextPage()
|
||||
void fetchNextPage()
|
||||
}, [isFetchingNextPage, hasNextPage, error, fetchNextPage])
|
||||
|
||||
const closeAllActiveElements = useCloseAllActiveElements()
|
||||
@@ -220,19 +225,15 @@ function HashtagScreenTab({
|
||||
|
||||
if (!hasSession) {
|
||||
return (
|
||||
<SearchError
|
||||
title={_(msg`Search is currently unavailable when logged out`)}>
|
||||
<SearchError title={l`Search is currently unavailable when logged out`}>
|
||||
<Text style={[a.text_md, a.text_center, a.leading_snug]}>
|
||||
<Trans>
|
||||
<InlineLinkText
|
||||
label={_(msg`Sign in`)}
|
||||
to={'#'}
|
||||
onPress={showSignIn}>
|
||||
<InlineLinkText label={l`Sign in`} to={'#'} onPress={showSignIn}>
|
||||
Sign in
|
||||
</InlineLinkText>
|
||||
<Text style={t.atoms.text_contrast_medium}> or </Text>
|
||||
<InlineLinkText
|
||||
label={_(msg`Create an account`)}
|
||||
label={l`Create an account`}
|
||||
to={'#'}
|
||||
onPress={showCreateAccount}>
|
||||
create an account
|
||||
@@ -256,7 +257,7 @@ function HashtagScreenTab({
|
||||
isError={isError}
|
||||
onRetry={refetch}
|
||||
emptyType="results"
|
||||
emptyMessage={_(msg`We couldn't find any results for that tag.`)}
|
||||
emptyMessage={l`We couldn't find any results for that tag.`}
|
||||
/>
|
||||
) : (
|
||||
<List
|
||||
@@ -264,7 +265,7 @@ function HashtagScreenTab({
|
||||
renderItem={renderItem}
|
||||
keyExtractor={keyExtractor}
|
||||
refreshing={isPTR}
|
||||
onRefresh={onRefresh}
|
||||
onRefresh={() => void onRefresh()}
|
||||
onEndReached={onEndReached}
|
||||
onEndReachedThreshold={4}
|
||||
onItemSeen={trackPostView}
|
||||
|
||||
Reference in New Issue
Block a user