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

Function AdAsComment

packages/shared/src/components/comments/AdAsComment.tsx:31–149  ·  view source on GitHub ↗
({ postId }: AdAsCommentProps)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected