MCPcopy Create free account
hub / github.com/dailydotdev/apps / AdAsComment

Function AdAsComment

packages/shared/src/components/comments/AdAsComment.tsx:38–178  ·  view source on GitHub ↗
({
  postId,
  source: postSource,
  isCompact = false,
}: AdAsCommentProps)

Source from the content-addressed store, hash-verified

36 isCompact?: boolean;
37}
38export const AdAsComment = ({
39 postId,
40 source: postSource,
41 isCompact = false,
42}: AdAsCommentProps): ReactElement => {
43 const { logEvent } = useLogContext();
44 const { user } = useAuthContext();
45 const { isPlus } = usePlusSubscription();
46 const isAdFree = shouldSkipSourceAds(postSource);
47
48 const {
49 data: ad,
50 isFetching,
51 isRefetching,
52 } = useAdQuery({
53 placement: AdPlacement.PostComment,
54 queryKey: generateQueryKey(RequestKey.Ads, user, postId),
55 enabled: !isAdFree,
56 staleTime: StaleTime.OneHour,
57 refreshOnPageView: true,
58 });
59
60 const onAdAction = useCallback(
61 (action: AdActions, extra?: Record<string, unknown>) => {
62 if (!ad) {
63 return;
64 }
65 logEvent(
66 adLogEvent(action, ad, {
67 extra: {
68 origin: 'post page',
69 ...extra,
70 },
71 }),
72 );
73 },
74 [logEvent, ad],
75 );
76
77 const onViewable = useCallback(
78 (data: ViewabilityData) =>
79 onAdAction(AdActions.Viewable, viewabilityLogExtra(data)),
80 [onAdAction],
81 );
82
83 const promotedText = useScrambler(
84 !ad ? undefined : `Promoted by ${ad.source}`,
85 );
86
87 useEffect(() => {
88 if (!ad || ad?.impressionStatus === ImpressionStatus.LOGGED) {
89 return;
90 }
91
92 onAdAction(AdActions.Impression);
93 ad.impressionStatus = ImpressionStatus.LOGGED;
94 }, [ad, onAdAction]);
95

Callers

nothing calls this directly

Calls 12

useLogContextFunction · 0.90
useAuthContextFunction · 0.90
usePlusSubscriptionFunction · 0.90
shouldSkipSourceAdsFunction · 0.90
useAdQueryFunction · 0.90
generateQueryKeyFunction · 0.90
adLogEventFunction · 0.90
viewabilityLogExtraFunction · 0.90
useScramblerFunction · 0.90
getAdFaviconImageLinkFunction · 0.90
logEventFunction · 0.85
onAdActionFunction · 0.85

Tested by

no test coverage detected