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