Remove useless TS checks

This commit is contained in:
Dan Abramov
2025-01-22 01:05:11 +00:00
parent 6538013484
commit ac3f0af851
+27 -32
View File
@@ -165,6 +165,7 @@ type CurrentSource = {
type VideoItem = { type VideoItem = {
moderation: ModerationDecision moderation: ModerationDecision
post: AppBskyFeedDefs.PostView post: AppBskyFeedDefs.PostView
video: AppBskyEmbedVideo.View
feedContext: string | undefined feedContext: string | undefined
} }
@@ -197,30 +198,30 @@ function Feed() {
const videos = useMemo(() => { const videos = useMemo(() => {
let vids = let vids =
data?.pages data?.pages.flatMap(page => {
.flatMap(page => { const items: {
const items: { _reactKey: string
_reactKey: string moderation: ModerationDecision
moderation: ModerationDecision post: AppBskyFeedDefs.PostView
post: AppBskyFeedDefs.PostView video: AppBskyEmbedVideo.View
feedContext: string | undefined feedContext: string | undefined
}[] = [] }[] = []
for (const slice of page.slices) { for (const slice of page.slices) {
const feedPost = slice.items.find( const feedPost = slice.items.find(
item => item.uri === slice.feedPostUri, item => item.uri === slice.feedPostUri,
) )
if (feedPost) { if (feedPost && AppBskyEmbedVideo.isView(feedPost.post.embed)) {
items.push({ items.push({
_reactKey: feedPost._reactKey, _reactKey: feedPost._reactKey,
moderation: feedPost.moderation, moderation: feedPost.moderation,
post: feedPost.post, post: feedPost.post,
feedContext: slice.feedContext, video: feedPost.post.embed,
}) feedContext: slice.feedContext,
} })
} }
return items }
}) return items
.filter(item => AppBskyEmbedVideo.isView(item.post.embed)) || [] }) ?? []
const startingVideoIndex = vids?.findIndex(video => { const startingVideoIndex = vids?.findIndex(video => {
return video.post.uri === params.initialPostUri return video.post.uri === params.initialPostUri
}) })
@@ -244,13 +245,7 @@ function Feed() {
const renderItem: ListRenderItem<VideoItem> = useCallback( const renderItem: ListRenderItem<VideoItem> = useCallback(
({item, index}) => { ({item, index}) => {
const {post} = item const {post, video} = item
// filtered above, here for TS
if (!post.embed || !AppBskyEmbedVideo.isView(post.embed)) {
return null
}
const player = players?.[index % 3] const player = players?.[index % 3]
const currentSource = currentSources[index % 3] const currentSource = currentSources[index % 3]
@@ -258,11 +253,11 @@ function Feed() {
<VideoItem <VideoItem
player={player} player={player}
post={post} post={post}
embed={post.embed} embed={video}
active={ active={
isFocused && isFocused &&
index === currentIndex && index === currentIndex &&
currentSource?.source === post.embed.playlist currentSource?.source === video.playlist
} }
adjacent={index === currentIndex - 1 || index === currentIndex + 1} adjacent={index === currentIndex - 1 || index === currentIndex + 1}
moderation={item.moderation} moderation={item.moderation}