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

Function usePostContent

packages/shared/src/hooks/usePostContent.ts:55–133  ·  view source on GitHub ↗
({
  origin,
  post,
}: UsePostContentProps)

Source from the content-addressed store, hash-verified

53};
54
55const usePostContent = ({
56 origin,
57 post,
58}: UsePostContentProps): UsePostContent => {
59 const id = post?.id;
60 const queryClient = useQueryClient();
61 const { logEvent } = useLogContext();
62 const { logOpts } = useActiveFeedContext();
63 const onReadArticle = useReadArticle({ origin, post });
64 const { commentsPermalink } = post;
65 const cid = ReferralCampaignKey.SharePost;
66 const { getShortUrl } = useGetShortUrl();
67 const [, copyLink] = useCopyPostLink();
68 const logShareEvent = useCallback(
69 (provider: ShareProvider) =>
70 logEvent(
71 postLogEvent(LogEvent.SharePost, post, {
72 extra: { provider, origin },
73 ...(logOpts && logOpts),
74 }),
75 ),
76 // eslint-disable-next-line react-hooks/exhaustive-deps
77 [origin, post, logOpts],
78 );
79
80 const onCopyLink = useCallback(async () => {
81 const shortLink = await getShortUrl(commentsPermalink, cid);
82 copyLink({ link: shortLink });
83 logShareEvent(ShareProvider.CopyLink);
84 }, [cid, commentsPermalink, copyLink, getShortUrl, logShareEvent]);
85
86 useSubscription(
87 () => ({
88 query: POSTS_ENGAGED_SUBSCRIPTION,
89 variables: {
90 ids: [id],
91 },
92 }),
93 {
94 next: (data: PostsEngaged) => {
95 if (data.postsEngaged.id === id) {
96 updatePostCache(queryClient, post.id, data.postsEngaged);
97 }
98 },
99 },
100 );
101
102 const loggedPostEvent = useRef<string | null>(null);
103
104 useEffect(() => {
105 if (!post) {
106 return;
107 }
108
109 if (loggedPostEvent.current === post.id) {
110 return;
111 }
112

Callers 6

PostContentRawFunction · 0.85
SquadPostContentRawFunction · 0.85
CollectionPostContentRawFunction · 0.85
PostFocusCardFunction · 0.85
PollPostContentRawFunction · 0.85

Calls 11

useLogContextFunction · 0.90
useActiveFeedContextFunction · 0.90
useGetShortUrlFunction · 0.90
useCopyPostLinkFunction · 0.90
postLogEventFunction · 0.90
updatePostCacheFunction · 0.90
isShareLikePostFunction · 0.90
useReadArticleFunction · 0.85
logEventFunction · 0.85
useSubscriptionFunction · 0.85
logShareEventFunction · 0.70

Tested by

no test coverage detected