Make types legit
This commit is contained in:
@@ -5,8 +5,8 @@ import {AppBskyEmbedVideo, AppBskyFeedDefs, AppBskyFeedPost} from '@atproto/api'
|
||||
import {msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {VIDEO_FEED_URI} from '#/lib/constants'
|
||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||
import {AuthorFilter} from '#/state/queries/post-feed'
|
||||
import {formatCount} from '#/view/com/util/numeric/format'
|
||||
import {PreviewableUserAvatar} from '#/view/com/util/UserAvatar'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
@@ -19,12 +19,24 @@ import {Link} from '#/components/Link'
|
||||
import {MediaInsetBorder} from '#/components/MediaInsetBorder'
|
||||
import {Text} from '#/components/Typography'
|
||||
|
||||
/**
|
||||
* Kind of like `FeedDescriptor` but not
|
||||
*/
|
||||
export type SourceContext =
|
||||
| {type: 'feedgen'; uri: string; initialPostUri?: string}
|
||||
| {
|
||||
type: 'author'
|
||||
did: string
|
||||
filter: AuthorFilter
|
||||
initialPostUri?: string
|
||||
}
|
||||
|
||||
export function VideoPostCard({
|
||||
post,
|
||||
sourceFeedUri = VIDEO_FEED_URI,
|
||||
sourceContext,
|
||||
}: {
|
||||
post: AppBskyFeedDefs.PostView
|
||||
sourceFeedUri?: string
|
||||
sourceContext: SourceContext
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const {_, i18n} = useLingui()
|
||||
@@ -57,8 +69,8 @@ export function VideoPostCard({
|
||||
to={{
|
||||
screen: 'VideoFeed',
|
||||
params: {
|
||||
feedUri: sourceFeedUri,
|
||||
postUri: post.uri,
|
||||
...sourceContext,
|
||||
initialPostUri: post.uri,
|
||||
},
|
||||
}}
|
||||
onPressIn={onPressIn}
|
||||
|
||||
@@ -3,14 +3,14 @@ import {AppBskyEmbedVideo} from '@atproto/api'
|
||||
|
||||
import {FeedPostSliceItem} from '#/state/queries/post-feed'
|
||||
import {atoms as a, useGutters} from '#/alf'
|
||||
import {VideoPostCard} from '#/components/VideoPostCard'
|
||||
import {SourceContext,VideoPostCard} from '#/components/VideoPostCard'
|
||||
|
||||
export function PostFeedVideoGridRow({
|
||||
slices,
|
||||
sourceFeedUri,
|
||||
sourceContext,
|
||||
}: {
|
||||
slices: FeedPostSliceItem[]
|
||||
sourceFeedUri: string
|
||||
sourceContext: SourceContext
|
||||
}) {
|
||||
const gutters = useGutters(['base', 'base', 0, 'base'])
|
||||
const posts = slices
|
||||
@@ -28,7 +28,7 @@ export function PostFeedVideoGridRow({
|
||||
<View style={[a.flex_row, a.gap_sm]}>
|
||||
{posts.map(post => (
|
||||
<View key={post.uri} style={[a.flex_1]}>
|
||||
<VideoPostCard post={post} sourceFeedUri={sourceFeedUri} />
|
||||
<VideoPostCard post={post} sourceContext={sourceContext} />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import {NavigationState, PartialState} from '@react-navigation/native'
|
||||
import type {NativeStackNavigationProp} from '@react-navigation/native-stack'
|
||||
|
||||
import {SourceContext as VideoFeedSourceContext} from '#/components/VideoPostCard'
|
||||
|
||||
export type {NativeStackScreenProps} from '@react-navigation/native-stack'
|
||||
|
||||
export type CommonNavigatorParams = {
|
||||
@@ -57,7 +59,7 @@ export type CommonNavigatorParams = {
|
||||
StarterPackShort: {code: string}
|
||||
StarterPackWizard: undefined
|
||||
StarterPackEdit: {rkey?: string}
|
||||
VideoFeed: {feedUri: string; postUri?: string}
|
||||
VideoFeed: VideoFeedSourceContext
|
||||
}
|
||||
|
||||
export type BottomTabNavigatorParams = CommonNavigatorParams & {
|
||||
|
||||
@@ -111,6 +111,16 @@ export function VibeScreen({}: Props) {
|
||||
function YoloFeed() {
|
||||
const {params} = useRoute<RouteProp<CommonNavigatorParams, 'VideoFeed'>>()
|
||||
const isFocused = useIsFocused()
|
||||
const feedDesc = useMemo(() => {
|
||||
switch (params.type) {
|
||||
case 'feedgen':
|
||||
return `feedgen|${params.uri}` as const
|
||||
case 'author':
|
||||
return `author|${params.did}|${params.filter}` as const
|
||||
default:
|
||||
throw new Error(`Invalid video feed params ${JSON.stringify(params)}`)
|
||||
}
|
||||
}, [params])
|
||||
const {
|
||||
data,
|
||||
isFetching,
|
||||
@@ -118,13 +128,13 @@ function YoloFeed() {
|
||||
hasNextPage,
|
||||
isFetchingNextPage,
|
||||
fetchNextPage,
|
||||
} = usePostFeedQuery(`feedgen|${params.feedUri}`)
|
||||
} = usePostFeedQuery(feedDesc)
|
||||
|
||||
let videos = data?.pages.flatMap(page =>
|
||||
page.slices.flatMap(slice => slice.items),
|
||||
)
|
||||
const startingVideoIndex = videos?.findIndex(video => {
|
||||
return video.post.uri === params.postUri
|
||||
return video.post.uri === params.initialPostUri
|
||||
})
|
||||
if (videos && startingVideoIndex && startingVideoIndex > -1) {
|
||||
videos = videos.slice(startingVideoIndex)
|
||||
|
||||
@@ -44,7 +44,7 @@ import {
|
||||
} from './util'
|
||||
|
||||
type ActorDid = string
|
||||
type AuthorFilter =
|
||||
export type AuthorFilter =
|
||||
| 'posts_with_replies'
|
||||
| 'posts_no_replies'
|
||||
| 'posts_and_author_threads'
|
||||
|
||||
@@ -583,7 +583,10 @@ let PostFeed = ({
|
||||
return (
|
||||
<PostFeedVideoGridRow
|
||||
slices={row.slices}
|
||||
sourceFeedUri={row.sourceFeedUri}
|
||||
sourceContext={{
|
||||
type: 'feedgen',
|
||||
uri: row.sourceFeedUri,
|
||||
}}
|
||||
/>
|
||||
)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user