({
post,
tag,
className,
}: PostTopicSignupProps)
| 25 | } |
| 26 | |
| 27 | export function PostTopicSignup({ |
| 28 | post, |
| 29 | tag, |
| 30 | className, |
| 31 | }: PostTopicSignupProps): ReactElement { |
| 32 | const { tokenRefreshed } = useAuthContext(); |
| 33 | const { logEvent } = useLogContext(); |
| 34 | const [ref, inView] = useInView({ triggerOnce: true }); |
| 35 | const enabled = tokenRefreshed && inView; |
| 36 | const { data: titles } = useQuery({ |
| 37 | ...tagTitlesQueryOptions(), |
| 38 | enabled, |
| 39 | }); |
| 40 | const { data } = useQuery({ |
| 41 | ...postTopicSignupQueryOptions(post.id, tag), |
| 42 | enabled, |
| 43 | }); |
| 44 | const topic = titles?.[tag] || `#${tag}`; |
| 45 | const previews = (data?.similarPosts ?? []) |
| 46 | .filter( |
| 47 | (preview, index, posts) => |
| 48 | preview.id !== post.id && |
| 49 | posts.findIndex(({ id }) => id === preview.id) === index, |
| 50 | ) |
| 51 | .slice(0, POST_TOPIC_SIGNUP_PREVIEW_COUNT); |
| 52 | const extra = JSON.stringify({ origin: 'post topic signup', tag }); |
| 53 | |
| 54 | useLogEventOnce( |
| 55 | () => ({ |
| 56 | event_name: LogEvent.Impression, |
| 57 | target_type: TargetType.PostTopicSignup, |
| 58 | target_id: post.id, |
| 59 | extra, |
| 60 | }), |
| 61 | { condition: inView }, |
| 62 | ); |
| 63 | |
| 64 | return ( |
| 65 | <div ref={ref} className={className}> |
| 66 | <SignupWidget |
| 67 | title={`Get more posts about ${topic}`} |
| 68 | description="Create a free account to follow your favorite topics and build your own developer feed." |
| 69 | trigger={AuthTriggers.PostPage} |
| 70 | centered |
| 71 | > |
| 72 | {previews.length > 0 && ( |
| 73 | <ul |
| 74 | aria-label={`More posts about ${topic}`} |
| 75 | className={classNames( |
| 76 | 'mt-6 grid w-full max-w-lg grid-cols-1 gap-3 text-left', |
| 77 | previews.length > 1 && 'tablet:grid-cols-2', |
| 78 | )} |
| 79 | > |
| 80 | {previews.map((preview) => ( |
| 81 | <li key={preview.id}> |
| 82 | <Link href={getPostPath(preview)} passHref prefetch={false}> |
| 83 | <a |
| 84 | href={getPostPath(preview)} |
nothing calls this directly
no test coverage detected