Simplify logic

This commit is contained in:
Dan Abramov
2025-01-18 23:33:09 +00:00
parent 70bd229e34
commit ad680bc484
2 changed files with 18 additions and 19 deletions
+4 -10
View File
@@ -7,7 +7,7 @@ import {FEEDBACK_FEEDS, STAGING_FEEDS} from '#/lib/constants'
import {logEvent} from '#/lib/statsig/statsig'
import {logger} from '#/logger'
import {FeedDescriptor, FeedPostSliceItem} from '#/state/queries/post-feed'
import {getFeedPostSlice} from '#/view/com/posts/PostFeed'
import {getItemsForFeedback} from '#/view/com/posts/PostFeed'
import {useAgent} from './session'
type StateContext = {
@@ -102,21 +102,15 @@ export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) {
if (!enabled) {
return
}
const slice = getFeedPostSlice(feedItem)
if (slice === null) {
return
}
for (const [i, postItem] of slice.items.entries()) {
const items = getItemsForFeedback(feedItem)
for (const {item: postItem, feedContext} of items) {
if (!history.current.has(postItem)) {
history.current.add(postItem)
queue.current.add(
toString({
item: postItem.uri,
event: 'app.bsky.feed.defs#interactionSeen',
feedContext:
slice.type === 'videoGridRow'
? slice.feedContexts?.[i]
: slice.feedContext,
feedContext,
}),
)
sendToFeed()
+14 -9
View File
@@ -124,18 +124,23 @@ type FeedRow =
key: string
}
export function getFeedPostSlice(feedRow: FeedRow): {
items: FeedPostSliceItem[]
type: 'sliceItem' | 'videoGridRow'
feedContext?: string | undefined
feedContexts?: (string | undefined)[]
} | null {
export function getItemsForFeedback(feedRow: FeedRow):
| {
item: FeedPostSliceItem
feedContext: string | undefined
}[] {
if (feedRow.type === 'sliceItem') {
return {...feedRow.slice, type: 'sliceItem'}
return feedRow.slice.items.map(item => ({
item,
feedContext: feedRow.slice.feedContext,
}))
} else if (feedRow.type === 'videoGridRow') {
return feedRow
return feedRow.items.map((item, i) => ({
item,
feedContext: feedRow.feedContexts[i],
}))
} else {
return null
return []
}
}