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

Function PostCapsule

packages/shared/src/components/post/PostCapsule.tsx:98–305  ·  view source on GitHub ↗
({
  post,
  onCommentClick,
}: PostCapsuleProps)

Source from the content-addressed store, hash-verified

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.
98export 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) {

Callers

nothing calls this directly

Calls 15

useIsPhoneFunction · 0.90
useRegisterShellFieldFunction · 0.90
useAuthContextFunction · 0.90
useLazyModalFunction · 0.90
useBlockPostPanelFunction · 0.90
useVotePostFunction · 0.90
useBookmarkPostFunction · 0.90
usePostActionsFunction · 0.90
useBrandSponsorshipFunction · 0.90
useCanAwardUserFunction · 0.90
useGetShortUrlFunction · 0.90
useCopyPostLinkFunction · 0.90

Tested by

no test coverage detected