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

Function AdAsComment

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected