-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1603 from SeedCompany/comments/tweaks
Comments Tweaks
- Loading branch information
Showing
8 changed files
with
42 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
query CommentThreadsList($resourceId: ID!, $input: CommentThreadListInput) { | ||
commentThreads(resource: $resourceId, input: $input) { | ||
canCreate | ||
items { | ||
...commentThread | ||
commentable(resource: $resourceId) { | ||
id | ||
commentThreads(input: $input) { | ||
canCreate | ||
items { | ||
...commentThread | ||
} | ||
...Pagination | ||
} | ||
...Pagination | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
query ThreadCount($id: ID!) { | ||
commentable(resource: $id) { | ||
id | ||
commentThreads { | ||
total | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,36 @@ | ||
import { useQuery } from '@apollo/client'; | ||
import { Comment } from '@mui/icons-material'; | ||
import { Badge } from '@mui/material'; | ||
import { Badge, Tooltip } from '@mui/material'; | ||
import { Except } from 'type-fest'; | ||
import { Feature } from '../Feature'; | ||
import { IconButton, IconButtonProps } from '../IconButton'; | ||
import { useCommentsContext } from './CommentsContext'; | ||
import { ThreadCountDocument } from './ThreadCount.graphql'; | ||
|
||
export type ToggleCommentsButtonProps = Except<IconButtonProps, 'children'>; | ||
|
||
export const ToggleCommentsButton = ({ | ||
...rest | ||
}: ToggleCommentsButtonProps) => { | ||
const { toggleCommentsBar, resourceCommentsTotal } = 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; | ||
|
||
return ( | ||
<Feature flag="comments" match={true}> | ||
<IconButton onClick={() => toggleCommentsBar()} {...rest}> | ||
<Badge badgeContent={resourceCommentsTotal} color="error"> | ||
<Comment /> | ||
</Badge> | ||
</IconButton> | ||
<Tooltip title={`${isCommentsBarOpen ? 'Hide' : 'Show'} Comments`}> | ||
<IconButton onClick={() => toggleCommentsBar()} {...rest}> | ||
<Badge badgeContent={total} color="primary"> | ||
<Comment /> | ||
</Badge> | ||
</IconButton> | ||
</Tooltip> | ||
</Feature> | ||
); | ||
}; |