({
post,
onCommentClick,
}: PostCapsuleProps)
| 96 | // reading, the bar slides below the screen and the capsule takes its slot |
| 97 | // at the compact size, the way the search field does. |
| 98 | export function PostCapsule({ |
| 99 | post, |
| 100 | onCommentClick, |
| 101 | }: PostCapsuleProps): ReactElement | null { |
| 102 | const origin = LogOrigin.ArticlePage; |
| 103 | const isPhone = useIsPhone(); |
| 104 | const { p, bottom, translateY, height } = usePostCapsulePosition(); |
| 105 | useRegisterShellField(isPhone); |
| 106 | // Icons swap in with a short scale and blur once the reader has touched |
| 107 | // the capsule; the first paint shows them as they are. |
| 108 | const [isTouched, setIsTouched] = useState(false); |
| 109 | |
| 110 | const { user, showLogin } = useAuthContext(); |
| 111 | const { openModal } = useLazyModal(); |
| 112 | const { onClose, onShowPanel } = useBlockPostPanel(post); |
| 113 | const { toggleUpvote, toggleDownvote } = useVotePost(); |
| 114 | const { toggleBookmark } = useBookmarkPost(); |
| 115 | const { onInteract } = usePostActions({ post }); |
| 116 | const { getUpvoteAnimation } = useBrandSponsorship(); |
| 117 | const canAward = useCanAwardUser({ |
| 118 | sendingUser: user, |
| 119 | receivingUser: post.author as LoggedUser | undefined, |
| 120 | }); |
| 121 | |
| 122 | // Match the desktop `PostActions` copy flow: fetch the short URL imperatively |
| 123 | // on click so anonymous users still get a usable (long) link instead of a no-op. |
| 124 | const { getShortUrl } = useGetShortUrl(); |
| 125 | const [, copyLink] = useCopyPostLink(); |
| 126 | const { logEvent } = useLogContext(); |
| 127 | |
| 128 | const isUpvoteActive = post?.userState?.vote === UserVote.Up; |
| 129 | const isDownvoteActive = post?.userState?.vote === UserVote.Down; |
| 130 | const isAwarded = !!post?.userState?.awarded; |
| 131 | const isCompact = p === 1; |
| 132 | const upvoteCount = isCompact ? undefined : post.numUpvotes; |
| 133 | const commentCount = isCompact ? undefined : post.numComments; |
| 134 | |
| 135 | const brandAnimation = useMemo(() => { |
| 136 | const animationResult = getUpvoteAnimation(post.tags || []); |
| 137 | if ( |
| 138 | !animationResult.shouldAnimate || |
| 139 | !animationResult.colors || |
| 140 | !animationResult.config |
| 141 | ) { |
| 142 | return null; |
| 143 | } |
| 144 | return { |
| 145 | colors: animationResult.colors, |
| 146 | config: animationResult.config, |
| 147 | brandLogo: animationResult.brandLogo, |
| 148 | }; |
| 149 | }, [getUpvoteAnimation, post.tags]); |
| 150 | |
| 151 | const onToggleUpvote = async () => { |
| 152 | if (post?.userState?.vote === UserVote.None) { |
| 153 | onClose(true); |
| 154 | } |
| 155 | if (post?.userState?.vote !== UserVote.Up) { |
nothing calls this directly
no test coverage detected