import React, { useEffect, useState, useCallback } from "react"; // editor import { EditorMenuItemNames, EditorRefApi } from "@plane/lite-text-editor"; // ui import { Button, Tooltip } from "@plane/ui"; // constants import { TOOLBAR_ITEMS } from "@/constants/editor"; // helpers import { cn } from "@/helpers/common.helper"; type Props = { executeCommand: (commandName: EditorMenuItemNames) => void; handleSubmit: (event: React.MouseEvent) => void; isCommentEmpty: boolean; isSubmitting: boolean; showSubmitButton: boolean; editorRef: React.MutableRefObject | null; }; const toolbarItems = TOOLBAR_ITEMS.lite; export const IssueCommentToolbar: React.FC = (props) => { const { executeCommand, handleSubmit, isCommentEmpty, editorRef, isSubmitting, showSubmitButton } = props; // states const [activeStates, setActiveStates] = useState>({}); // Function to update active states const updateActiveStates = useCallback(() => { if (editorRef?.current) { const newActiveStates: Record = {}; Object.values(toolbarItems) .flat() .forEach((item) => { // Assert that editorRef.current is not null newActiveStates[item.key] = (editorRef.current as EditorRefApi).isMenuItemActive(item.key); }); setActiveStates(newActiveStates); } }, [editorRef]); // useEffect to call updateActiveStates when isActive prop changes useEffect(() => { if (!editorRef?.current) return; const unsubscribe = editorRef.current.onStateChange(updateActiveStates); updateActiveStates(); return () => unsubscribe(); }, [editorRef, updateActiveStates]); return (
{Object.keys(toolbarItems).map((key, index) => (
{toolbarItems[key].map((item) => ( {item.name} {item.shortcut && {item.shortcut.join(" + ")}}

} >
))}
))}
{showSubmitButton && (
)}
); };