({ postId }: AdAsCommentProps)
| 29 | postId: string; |
| 30 | } |
| 31 | export 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) { |
nothing calls this directly
no test coverage detected