Merge branch 'hailey/expo-oauth-helper' into hailey/oauth
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
export type Gate =
|
||||
// Keep this alphabetic please.
|
||||
| 'autoexpand_suggestions_on_profile_follow'
|
||||
| 'disable_min_shell_on_foregrounding'
|
||||
| 'disable_poll_on_discover'
|
||||
| 'new_search'
|
||||
| 'show_follow_back_label'
|
||||
| 'start_session_with_following'
|
||||
@@ -9,14 +9,21 @@ import {
|
||||
} from 'statsig-react-native-expo'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {IS_TESTFLIGHT} from 'lib/app-info'
|
||||
import {useSession} from '../../state/session'
|
||||
import {LogEvents} from './events'
|
||||
import {Gate} from './gates'
|
||||
|
||||
export type {LogEvents}
|
||||
|
||||
const statsigOptions = {
|
||||
environment: {
|
||||
tier: process.env.NODE_ENV === 'development' ? 'development' : 'production',
|
||||
tier:
|
||||
process.env.NODE_ENV === 'development'
|
||||
? 'development'
|
||||
: IS_TESTFLIGHT
|
||||
? 'staging'
|
||||
: 'production',
|
||||
},
|
||||
// Don't block on waiting for network. The fetched config will kick in on next load.
|
||||
// This ensures the UI is always consistent and doesn't update mid-session.
|
||||
@@ -69,7 +76,7 @@ export function logEvent<E extends keyof LogEvents>(
|
||||
}
|
||||
}
|
||||
|
||||
export function useGate(gateName: string) {
|
||||
export function useGate(gateName: Gate): boolean {
|
||||
const {isLoading, value} = useStatsigGate(gateName)
|
||||
if (isLoading) {
|
||||
// This should not happen because of waitForInitialization={true}.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -19,6 +19,7 @@ import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager'
|
||||
import {CustomFeedEmptyState} from 'view/com/posts/CustomFeedEmptyState'
|
||||
import {FollowingEmptyState} from 'view/com/posts/FollowingEmptyState'
|
||||
import {FollowingEndOfFeed} from 'view/com/posts/FollowingEndOfFeed'
|
||||
import {RnCryptoKey} from '../../../modules/expo-bluesky-oauth-client'
|
||||
import {HomeLoggedOutCTA} from '../com/auth/HomeLoggedOutCTA'
|
||||
import {HomeHeader} from '../com/home/HomeHeader'
|
||||
|
||||
@@ -51,6 +52,18 @@ function HomeScreenReady({
|
||||
preferences: UsePreferencesQueryResponse
|
||||
pinnedFeedInfos: FeedSourceInfo[]
|
||||
}) {
|
||||
React.useEffect(() => {
|
||||
;(async () => {
|
||||
const key = await RnCryptoKey.generate(undefined, ['ES256'], false)
|
||||
console.log('public', key.publicJwk)
|
||||
const jwt = await key.createJwt(
|
||||
{alg: 'ES256', kid: key.kid},
|
||||
{sub: 'test'},
|
||||
)
|
||||
console.log(jwt)
|
||||
})()
|
||||
}, [])
|
||||
|
||||
const allFeeds = React.useMemo(() => {
|
||||
const feeds: FeedDescriptor[] = []
|
||||
feeds.push('home')
|
||||
|
||||
@@ -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 {useGate} from '#/lib/statsig/statsig'
|
||||
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 = useGate('new_search')
|
||||
|
||||
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: <SearchScreenPostResults query={query} sort="top" />,
|
||||
},
|
||||
{
|
||||
title: _(msg`Latest`),
|
||||
component: <SearchScreenPostResults query={query} sort="latest" />,
|
||||
},
|
||||
{
|
||||
title: _(msg`People`),
|
||||
component: <SearchScreenUserResults query={query} />,
|
||||
},
|
||||
]
|
||||
} else {
|
||||
return [
|
||||
{
|
||||
title: _(msg`People`),
|
||||
component: <SearchScreenUserResults query={query} />,
|
||||
},
|
||||
]
|
||||
}
|
||||
} else {
|
||||
if (hasSession) {
|
||||
return [
|
||||
{
|
||||
title: _(msg`Posts`),
|
||||
component: <SearchScreenPostResults query={query} />,
|
||||
},
|
||||
{
|
||||
title: _(msg`Users`),
|
||||
component: <SearchScreenUserResults query={query} />,
|
||||
},
|
||||
]
|
||||
} else {
|
||||
return [
|
||||
{
|
||||
title: _(msg`Users`),
|
||||
component: <SearchScreenUserResults query={query} />,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}, [hasSession, isNewSearch, _, query])
|
||||
|
||||
if (hasSession) {
|
||||
return query ? (
|
||||
<Pager
|
||||
@@ -347,16 +404,13 @@ export function SearchScreenInner({
|
||||
<CenteredView
|
||||
sideBorders
|
||||
style={[pal.border, pal.view, styles.tabBarContainer]}>
|
||||
<TabBar items={SECTIONS_LOGGEDIN} {...props} />
|
||||
<TabBar items={sections.map(section => section.title)} {...props} />
|
||||
</CenteredView>
|
||||
)}
|
||||
initialPage={0}>
|
||||
<View>
|
||||
<SearchScreenPostResults query={query} />
|
||||
</View>
|
||||
<View>
|
||||
<SearchScreenUserResults query={query} />
|
||||
</View>
|
||||
{sections.map((section, i) => (
|
||||
<View key={i}>{section.component}</View>
|
||||
))}
|
||||
</Pager>
|
||||
) : (
|
||||
<View>
|
||||
@@ -389,13 +443,13 @@ export function SearchScreenInner({
|
||||
<CenteredView
|
||||
sideBorders
|
||||
style={[pal.border, pal.view, styles.tabBarContainer]}>
|
||||
<TabBar items={SECTIONS_LOGGEDOUT} {...props} />
|
||||
<TabBar items={sections.map(section => section.title)} {...props} />
|
||||
</CenteredView>
|
||||
)}
|
||||
initialPage={0}>
|
||||
<View>
|
||||
<SearchScreenUserResults query={query} />
|
||||
</View>
|
||||
{sections.map((section, i) => (
|
||||
<View key={i}>{section.component}</View>
|
||||
))}
|
||||
</Pager>
|
||||
) : (
|
||||
<CenteredView sideBorders style={pal.border}>
|
||||
|
||||
Reference in New Issue
Block a user