From 0608412a6d2d6fd407a7ddedb41cc18ddcacbaa2 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 16 Jan 2025 17:36:59 -0600 Subject: [PATCH] Make types legit --- src/components/VideoPostCard.tsx | 22 ++++++++++++++----- src/components/feeds/PostFeedVideoGridRow.tsx | 8 +++---- src/lib/routes/types.ts | 4 +++- src/screens/Feeds/VibeScreen.tsx | 14 ++++++++++-- src/state/queries/post-feed.ts | 2 +- src/view/com/posts/PostFeed.tsx | 5 ++++- 6 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/components/VideoPostCard.tsx b/src/components/VideoPostCard.tsx index c30eea3e69..e5898226a4 100644 --- a/src/components/VideoPostCard.tsx +++ b/src/components/VideoPostCard.tsx @@ -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} diff --git a/src/components/feeds/PostFeedVideoGridRow.tsx b/src/components/feeds/PostFeedVideoGridRow.tsx index 222290377b..60372bef48 100644 --- a/src/components/feeds/PostFeedVideoGridRow.tsx +++ b/src/components/feeds/PostFeedVideoGridRow.tsx @@ -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({ {posts.map(post => ( - + ))} diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts index a9570a9dbd..954eb30bef 100644 --- a/src/lib/routes/types.ts +++ b/src/lib/routes/types.ts @@ -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 & { diff --git a/src/screens/Feeds/VibeScreen.tsx b/src/screens/Feeds/VibeScreen.tsx index 41f3718645..579fe9120e 100644 --- a/src/screens/Feeds/VibeScreen.tsx +++ b/src/screens/Feeds/VibeScreen.tsx @@ -111,6 +111,16 @@ export function VibeScreen({}: Props) { function YoloFeed() { const {params} = useRoute>() 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) diff --git a/src/state/queries/post-feed.ts b/src/state/queries/post-feed.ts index 2eb604627e..61dabf5f10 100644 --- a/src/state/queries/post-feed.ts +++ b/src/state/queries/post-feed.ts @@ -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' diff --git a/src/view/com/posts/PostFeed.tsx b/src/view/com/posts/PostFeed.tsx index 0ac1aa1a45..32cdea84e2 100644 --- a/src/view/com/posts/PostFeed.tsx +++ b/src/view/com/posts/PostFeed.tsx @@ -583,7 +583,10 @@ let PostFeed = ({ return ( ) } else {