Handle passed through params
This commit is contained in:
@@ -24,13 +24,15 @@ import {
|
|||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {
|
import {
|
||||||
|
RouteProp,
|
||||||
useFocusEffect,
|
useFocusEffect,
|
||||||
useIsFocused,
|
useIsFocused,
|
||||||
useNavigation,
|
useNavigation,
|
||||||
|
useRoute,
|
||||||
} from '@react-navigation/native'
|
} from '@react-navigation/native'
|
||||||
import {NativeStackScreenProps} from '@react-navigation/native-stack'
|
import {NativeStackScreenProps} from '@react-navigation/native-stack'
|
||||||
|
|
||||||
import {HITSLOP_20, VIBES_FEED_URI} from '#/lib/constants'
|
import {HITSLOP_20} from '#/lib/constants'
|
||||||
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
||||||
import {CommonNavigatorParams, NavigationProp} from '#/lib/routes/types'
|
import {CommonNavigatorParams, NavigationProp} from '#/lib/routes/types'
|
||||||
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||||
@@ -107,6 +109,7 @@ export function VibeScreen({}: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function YoloFeed() {
|
function YoloFeed() {
|
||||||
|
const {params} = useRoute<RouteProp<CommonNavigatorParams, 'TempVibe'>>()
|
||||||
const isFocused = useIsFocused()
|
const isFocused = useIsFocused()
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
@@ -115,7 +118,9 @@ function YoloFeed() {
|
|||||||
hasNextPage,
|
hasNextPage,
|
||||||
isFetchingNextPage,
|
isFetchingNextPage,
|
||||||
fetchNextPage,
|
fetchNextPage,
|
||||||
} = usePostFeedQuery(`feedgen|${VIBES_FEED_URI}`)
|
} = usePostFeedQuery(`feedgen|${params.feedUri}`, {
|
||||||
|
initialCursor: params.cursor,
|
||||||
|
})
|
||||||
|
|
||||||
const videos = data?.pages.flatMap(page =>
|
const videos = data?.pages.flatMap(page =>
|
||||||
page.slices.flatMap(slice => slice.items),
|
page.slices.flatMap(slice => slice.items),
|
||||||
|
|||||||
@@ -61,9 +61,10 @@ export type FeedDescriptor =
|
|||||||
export interface FeedParams {
|
export interface FeedParams {
|
||||||
mergeFeedEnabled?: boolean
|
mergeFeedEnabled?: boolean
|
||||||
mergeFeedSources?: string[]
|
mergeFeedSources?: string[]
|
||||||
|
initialCursor?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RQPageParam = {cursor: string | undefined; api: FeedAPI} | undefined
|
type RQPageParam = {cursor: string | undefined; api?: FeedAPI} | undefined
|
||||||
|
|
||||||
export const RQKEY_ROOT = 'post-feed'
|
export const RQKEY_ROOT = 'post-feed'
|
||||||
export function RQKEY(feedDesc: FeedDescriptor, params?: FeedParams) {
|
export function RQKEY(feedDesc: FeedDescriptor, params?: FeedParams) {
|
||||||
@@ -171,24 +172,24 @@ export function usePostFeedQuery(
|
|||||||
queryKey: RQKEY(feedDesc, params),
|
queryKey: RQKEY(feedDesc, params),
|
||||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||||
logger.debug('usePostFeedQuery', {feedDesc, cursor: pageParam?.cursor})
|
logger.debug('usePostFeedQuery', {feedDesc, cursor: pageParam?.cursor})
|
||||||
const {api, cursor} = pageParam
|
console.log('PAGE', feedDesc, pageParam?.cursor)
|
||||||
? pageParam
|
const cursor = pageParam?.cursor
|
||||||
: {
|
let api = pageParam?.api
|
||||||
api: createApi({
|
if (!api) {
|
||||||
feedDesc,
|
api = createApi({
|
||||||
feedParams: params || {},
|
feedDesc,
|
||||||
feedTuners,
|
feedParams: params || {},
|
||||||
agent,
|
feedTuners,
|
||||||
// Not in the query key because they don't change:
|
agent,
|
||||||
userInterests,
|
// Not in the query key because they don't change:
|
||||||
// Not in the query key. Reacting to it switching isn't important:
|
userInterests,
|
||||||
enableFollowingToDiscoverFallback,
|
// Not in the query key. Reacting to it switching isn't important:
|
||||||
}),
|
enableFollowingToDiscoverFallback,
|
||||||
cursor: undefined,
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await api.fetch({cursor, limit: fetchLimit})
|
const res = await api!.fetch({cursor, limit: fetchLimit})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this is a public view, we need to check if posts fail moderation.
|
* If this is a public view, we need to check if posts fail moderation.
|
||||||
@@ -223,7 +224,7 @@ export function usePostFeedQuery(
|
|||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
initialPageParam: undefined,
|
initialPageParam: {api: undefined, cursor: params?.initialCursor},
|
||||||
getNextPageParam: lastPage =>
|
getNextPageParam: lastPage =>
|
||||||
lastPage.cursor
|
lastPage.cursor
|
||||||
? {
|
? {
|
||||||
|
|||||||
Reference in New Issue
Block a user