a0b98a944f
* feat: introducing TextToDiagram v2 feature * fix: eslint issue * debug mermaid bundle size * tests: covering the utils * fix: import mock chunks dynamically to shrink the bundle size * fix: removing replay feature * fix: removing unused prop * fix: bumping workbox cache limit * snapshots + yarn.lock * bump mermaid-to-excalidraw@2 and split into its own chunk * bump node@20 * css tweaks * move files around & rewrite stream chunk schema * random naming & file structure refactor + some tweaks * fix preview theme * support custom warning renderer * label and css fix * fix and rwrite 429 handling * fix label --------- Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
93 lines
2.7 KiB
TypeScript
93 lines
2.7 KiB
TypeScript
import clsx from "clsx";
|
|
|
|
import { t } from "../../../i18n";
|
|
import { historyIcon, TrashIcon } from "../../icons";
|
|
import DropdownMenu from "../../dropdownMenu/DropdownMenu";
|
|
|
|
import { FilledButton } from "../../FilledButton";
|
|
|
|
import type { SavedChat } from "../types";
|
|
|
|
interface ChatHistoryMenuProps {
|
|
isOpen: boolean;
|
|
onToggle: () => void;
|
|
onClose: () => void;
|
|
onNewChat: () => void;
|
|
onRestoreChat: (chat: SavedChat) => void;
|
|
onDeleteChat: (chatId: string, event: React.MouseEvent) => void;
|
|
savedChats: SavedChat[];
|
|
activeSessionId: string;
|
|
disabled?: boolean;
|
|
isNewChatBtnVisible?: boolean;
|
|
}
|
|
|
|
export const ChatHistoryMenu = ({
|
|
isOpen,
|
|
onToggle,
|
|
onClose,
|
|
onNewChat,
|
|
onRestoreChat,
|
|
onDeleteChat,
|
|
isNewChatBtnVisible,
|
|
savedChats,
|
|
activeSessionId,
|
|
disabled,
|
|
}: ChatHistoryMenuProps) => {
|
|
return (
|
|
<div className="ttd-chat-history-menu">
|
|
{isNewChatBtnVisible && (
|
|
<FilledButton onClick={onNewChat} disabled={disabled}>
|
|
{t("chat.newChat")}
|
|
</FilledButton>
|
|
)}
|
|
{savedChats.length > 0 && (
|
|
<div className="ttd-dialog-panel__menu-wrapper">
|
|
<DropdownMenu open={isOpen}>
|
|
<DropdownMenu.Trigger
|
|
onToggle={onToggle}
|
|
className="ttd-dialog-menu-trigger"
|
|
disabled={disabled}
|
|
title={t("chat.menu")}
|
|
aria-label={t("chat.menu")}
|
|
>
|
|
{historyIcon}
|
|
</DropdownMenu.Trigger>
|
|
<DropdownMenu.Content
|
|
onClickOutside={onClose}
|
|
onSelect={onClose}
|
|
placement="bottom"
|
|
>
|
|
<>
|
|
{savedChats.map((chat) => (
|
|
<DropdownMenu.ItemCustom
|
|
key={chat.id}
|
|
className={clsx("ttd-chat-menu-item", {
|
|
"ttd-chat-menu-item--active": chat.id === activeSessionId,
|
|
})}
|
|
onClick={() => {
|
|
onRestoreChat(chat);
|
|
}}
|
|
>
|
|
<span className="ttd-chat-menu-item__title">
|
|
{chat.title}
|
|
</span>
|
|
<button
|
|
className="ttd-chat-menu-item__delete"
|
|
onClick={(e) => onDeleteChat(chat.id, e)}
|
|
title={t("chat.deleteChat")}
|
|
aria-label={t("chat.deleteChat")}
|
|
type="button"
|
|
>
|
|
{TrashIcon}
|
|
</button>
|
|
</DropdownMenu.ItemCustom>
|
|
))}
|
|
</>
|
|
</DropdownMenu.Content>
|
|
</DropdownMenu>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|