Add types for interactions and remove useMemo
This commit is contained in:
+24
-8
@@ -91,23 +91,39 @@ export const STAGING_FEEDS = [
|
||||
|
||||
export const FEEDBACK_FEEDS = [...PROD_FEEDS, ...STAGING_FEEDS]
|
||||
|
||||
export const PASSIVE_INTERACTIONS = [
|
||||
export const PASSIVE_FEEDBACK_INTERACTIONS = [
|
||||
'app.bsky.feed.defs#clickthroughItem',
|
||||
'app.bsky.feed.defs#clickthroughAuthor',
|
||||
'app.bsky.feed.defs#clickthroughReposter',
|
||||
'app.bsky.feed.defs#clickthroughEmbed',
|
||||
'app.bsky.feed.defs#interactionSeen',
|
||||
]
|
||||
] as const
|
||||
|
||||
export const DIRECT_INTERACTIONS = [
|
||||
export type PassiveFeedbackInteraction =
|
||||
(typeof PASSIVE_FEEDBACK_INTERACTIONS)[number]
|
||||
|
||||
export const DIRECT_FEEDBACK_INTERACTIONS = [
|
||||
'app.bsky.feed.defs#requestLess',
|
||||
'app.bsky.feed.defs#requestMore',
|
||||
]
|
||||
] as const
|
||||
|
||||
export const ALL_INTERACTIONS = [
|
||||
...PASSIVE_INTERACTIONS,
|
||||
...DIRECT_INTERACTIONS,
|
||||
]
|
||||
export type DirectFeedbackInteraction =
|
||||
(typeof DIRECT_FEEDBACK_INTERACTIONS)[number]
|
||||
|
||||
export const ALL_FEEDBACK_INTERACTIONS = [
|
||||
...PASSIVE_FEEDBACK_INTERACTIONS,
|
||||
...DIRECT_FEEDBACK_INTERACTIONS,
|
||||
] as const
|
||||
|
||||
export type FeedbackInteraction = (typeof ALL_FEEDBACK_INTERACTIONS)[number]
|
||||
|
||||
export function isFeedbackInteraction(
|
||||
interactionEvent: string,
|
||||
): interactionEvent is FeedbackInteraction {
|
||||
return ALL_FEEDBACK_INTERACTIONS.includes(
|
||||
interactionEvent as FeedbackInteraction,
|
||||
)
|
||||
}
|
||||
|
||||
export const POST_IMG_MAX = {
|
||||
width: 2000,
|
||||
|
||||
+22
-10
@@ -11,9 +11,11 @@ import {type AppBskyFeedDefs} from '@atproto/api'
|
||||
import throttle from 'lodash.throttle'
|
||||
|
||||
import {
|
||||
ALL_INTERACTIONS,
|
||||
DIRECT_INTERACTIONS,
|
||||
ALL_FEEDBACK_INTERACTIONS,
|
||||
DIRECT_FEEDBACK_INTERACTIONS,
|
||||
FEEDBACK_FEEDS,
|
||||
type FeedbackInteraction,
|
||||
isFeedbackInteraction,
|
||||
STAGING_FEEDS,
|
||||
} from '#/lib/constants'
|
||||
import {logEvent} from '#/lib/statsig/statsig'
|
||||
@@ -61,12 +63,7 @@ export function useFeedFeedback(
|
||||
const feedInfo = feed ? buildFeedInfo(feed) : null
|
||||
const enabled = !!feedInfo && feedInfo.acceptsInteractions && hasSession
|
||||
|
||||
const enabledInteractions = useMemo(() => {
|
||||
if (!enabled) {
|
||||
return []
|
||||
}
|
||||
return feedInfo.isDiscover ? ALL_INTERACTIONS : DIRECT_INTERACTIONS
|
||||
}, [enabled, feedInfo])
|
||||
const enabledInteractions = getEnabledInteractions(enabled, feedInfo)
|
||||
|
||||
const queue = useRef<Set<string>>(new Set())
|
||||
const history = useRef<
|
||||
@@ -89,8 +86,11 @@ export function useFeedFeedback(
|
||||
const interactions = Array.from(queue.current).map(toInteraction)
|
||||
queue.current.clear()
|
||||
|
||||
const interactionsToSend = interactions.filter(interaction =>
|
||||
enabledInteractions.includes(interaction.event ?? ''),
|
||||
const interactionsToSend = interactions.filter(
|
||||
interaction =>
|
||||
interaction.event &&
|
||||
isFeedbackInteraction(interaction.event) &&
|
||||
enabledInteractions.includes(interaction.event),
|
||||
)
|
||||
|
||||
if (interactionsToSend.length === 0) {
|
||||
@@ -259,6 +259,18 @@ function buildFeedInfo(feed: FeedSourceInfo | FeedDescriptor): FeedInfo | null {
|
||||
}
|
||||
}
|
||||
|
||||
function getEnabledInteractions(
|
||||
enabled: boolean,
|
||||
feedInfo: FeedInfo | null,
|
||||
): readonly FeedbackInteraction[] {
|
||||
if (!enabled || !feedInfo) {
|
||||
return []
|
||||
}
|
||||
return feedInfo.isDiscover
|
||||
? ALL_FEEDBACK_INTERACTIONS
|
||||
: DIRECT_FEEDBACK_INTERACTIONS
|
||||
}
|
||||
|
||||
function toString(interaction: AppBskyFeedDefs.Interaction): string {
|
||||
return `${interaction.item}|${interaction.event}|${
|
||||
interaction.feedContext || ''
|
||||
|
||||
Reference in New Issue
Block a user