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

Function useTrackPostView

packages/shared/src/hooks/post/useTrackPostView.ts:12–32  ·  view source on GitHub ↗
({
  post,
  shouldTrack = true,
}: UseTrackPostViewProps)

Source from the content-addressed store, hash-verified

10}
11
12export const useTrackPostView = ({
13 post,
14 shouldTrack = true,
15}: UseTrackPostViewProps): void => {
16 const { user } = useAuthContext();
17 const onSendViewPost = useViewPost();
18
19 useEffect(() => {
20 if (!shouldTrack || !post?.id || !user?.id) {
21 return;
22 }
23
24 // Nothing awaits this, so a rejected `mutateAsync` would surface as an
25 // unhandled rejection. A lost view is not worth reporting.
26 onSendViewPost(post.id).catch(() => undefined);
27 emitPatchyEvent({ type: 'post_open', tags: post.tags, post });
28 // Tags ride along with the id; a new array for the same post is no reason
29 // to count the view again.
30 // eslint-disable-next-line react-hooks/exhaustive-deps
31 }, [onSendViewPost, post?.id, shouldTrack, user?.id]);
32};

Callers 5

PostContentRawFunction · 0.90
SquadPostContentRawFunction · 0.90
CollectionPostContentRawFunction · 0.90
PostHybridContentRawFunction · 0.90
CompanionFunction · 0.90

Calls 3

useAuthContextFunction · 0.90
useViewPostFunction · 0.90
emitPatchyEventFunction · 0.90

Tested by

no test coverage detected