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

Function usePostComments

packages/shared/src/hooks/comments/usePostComments.ts:27–54  ·  view source on GitHub ↗
({
  postId,
  sortBy,
}: UsePostCommentsProps)

Source from the content-addressed store, hash-verified

25 * post has comments.
26 */
27export const usePostComments = ({
28 postId,
29 sortBy,
30}: UsePostCommentsProps): UsePostCommentsResult => {
31 const { tokenRefreshed } = useContext(AuthContext);
32 const { requestMethod } = useRequestProtocol();
33 const queryKey = generateCommentsQueryKey({ postId, sortBy });
34 const { data: comments, isLoading } = useQuery<PostCommentsData>({
35 queryKey,
36
37 queryFn: (): Promise<PostCommentsData> =>
38 requestMethod(
39 POST_COMMENTS_QUERY,
40 { postId, [initialDataKey]: comments, first: 500, sortBy },
41 { requestKey: JSON.stringify(queryKey) },
42 ),
43 enabled: !!postId && tokenRefreshed,
44 refetchInterval: 60 * 1000,
45 refetchOnWindowFocus: false,
46 });
47
48 return {
49 queryKey,
50 comments,
51 isLoading,
52 commentsCount: comments?.postComments?.edges?.length || 0,
53 };
54};

Callers 5

PostCommentsFunction · 0.90
PostEngagementsFunction · 0.90
EngagementRailFunction · 0.90
DiscussionMetaBarFunction · 0.90
PostDiscussionPanelFunction · 0.90

Calls 2

useRequestProtocolFunction · 0.90
generateCommentsQueryKeyFunction · 0.90

Tested by

no test coverage detected