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