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

Function AdAsComment

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

Source from the content-addressed store, hash-verified

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

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