| 1 | "use client"; |
| 2 | |
| 3 | import { MessageSquareTextIcon } from "lucide-react"; |
| 4 | import { useEditorRef, usePluginOption } from "platejs/react"; |
| 5 | |
| 6 | import { commentPlugin } from "@/components/plate/plugins/comment-kit"; |
| 7 | import { discussionPlugin } from "@/components/plate/plugins/discussion-kit"; |
| 8 | import { ToolbarButton } from "./toolbar"; |
| 9 | |
| 10 | export function CommentToolbarButton() { |
| 11 | const editor = useEditorRef(); |
| 12 | const currentUserId = usePluginOption(discussionPlugin, "currentUserId"); |
| 13 | const isDisabled = !currentUserId; |
| 14 | |
| 15 | return ( |
| 16 | <ToolbarButton |
| 17 | onMouseDown={(e) => e.preventDefault()} |
| 18 | onClick={() => { |
| 19 | if (isDisabled) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | editor.getTransforms(commentPlugin).comment.setDraft(); |
| 24 | }} |
| 25 | data-plate-prevent-overlay |
| 26 | disabled={isDisabled} |
| 27 | tooltip="Comment" |
| 28 | > |
| 29 | <MessageSquareTextIcon /> |
| 30 | </ToolbarButton> |
| 31 | ); |
| 32 | } |
| 33 |