From 0b4310b034eb8d793d9d761c5ae08aa3ac92ca26 Mon Sep 17 00:00:00 2001 From: Carson Full Date: Wed, 9 Oct 2024 18:57:04 -0500 Subject: [PATCH] Only go to network for thread count if sidebar is closed This way there are not two requests in flight for the same info --- src/components/Comments/ToggleCommentButton.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Comments/ToggleCommentButton.tsx b/src/components/Comments/ToggleCommentButton.tsx index 9ee992118..0d159c77d 100644 --- a/src/components/Comments/ToggleCommentButton.tsx +++ b/src/components/Comments/ToggleCommentButton.tsx @@ -12,11 +12,13 @@ export type ToggleCommentsButtonProps = Except; export const ToggleCommentsButton = ({ ...rest }: ToggleCommentsButtonProps) => { - const { resourceId, toggleCommentsBar } = useCommentsContext(); + const { resourceId, isCommentsBarOpen, toggleCommentsBar } = + useCommentsContext(); const { data } = useQuery(ThreadCountDocument, { variables: { id: resourceId! }, skip: !resourceId, + fetchPolicy: isCommentsBarOpen ? 'cache-only' : 'cache-first', }); const total = data?.commentable.commentThreads.total ?? 0;