/** * Copyright (c) 2023-present Plane Software, Inc. and contributors * SPDX-License-Identifier: AGPL-3.0-only * See the LICENSE file for details. */ import React, { useEffect, useState, useCallback } from "react"; // plane imports import { TOOLBAR_ITEMS } from "@plane/editor"; import type { ToolbarMenuItem, EditorRefApi } from "@plane/editor"; import { Button } from "@plane/propel/button"; import { Tooltip } from "@plane/propel/tooltip"; import { cn } from "@plane/utils"; type Props = { executeCommand: (item: ToolbarMenuItem) => void; handleSubmit: (event: React.MouseEvent) => void; isCommentEmpty: boolean; isSubmitting: boolean; showSubmitButton: boolean; editorRef: EditorRefApi | null; }; const toolbarItems = TOOLBAR_ITEMS.lite; export function IssueCommentToolbar(props: Props) { const { executeCommand, handleSubmit, isCommentEmpty, editorRef, isSubmitting, showSubmitButton } = props; // states const [activeStates, setActiveStates] = useState>({}); // Function to update active states const updateActiveStates = useCallback(() => { if (!editorRef) return; const newActiveStates: Record = {}; Object.values(toolbarItems) .flat() .forEach((item) => { // TODO: update this while toolbar homogenization // @ts-expect-error type mismatch here newActiveStates[item.renderKey] = editorRef.isMenuItemActive({ itemKey: item.itemKey, ...item.extraProps, }); }); setActiveStates(newActiveStates); }, [editorRef]); // useEffect to call updateActiveStates when isActive prop changes useEffect(() => { if (!editorRef) return; const unsubscribe = editorRef.onStateChange(updateActiveStates); updateActiveStates(); return () => unsubscribe(); }, [editorRef, updateActiveStates]); return (
{Object.keys(toolbarItems).map((key, index) => (
{toolbarItems[key].map((item) => { const isItemActive = activeStates[item.renderKey]; return ( {item.name} {item.shortcut && {item.shortcut.join(" + ")}}

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