UNPKG

@plteam/chat-ui

Version:

CUI Kit is a free and open-source library for creating AI assistant chat interfaces, built with React, Material UI, and TypeScript

36 lines (35 loc) 1.59 kB
import * as React from 'react'; import { DeleteIcon } from '../../icons'; import MdMenu from '../../ui/menu/MdMenu'; import { useObserverValue } from '../hooks/useObserverValue'; import { useHistoryContext } from '../core/history/HistoryContext'; const ThreadListItemMenu = ({ model }) => { const { slots, locale, threadActions, internal } = useHistoryContext(); const menuConfig = model.listGroups.menuConfig; const config = useObserverValue(menuConfig); const anchorEl = config?.anchorEl; const thread = config?.thread; const handleClose = () => { if (menuConfig.value) { menuConfig.value = { anchorEl: null, thread: menuConfig.value.thread, }; } }; const handleDelete = () => { handleClose(); if (thread && internal) { internal.model.deleteItem.value = thread.data; } }; return (React.createElement(MdMenu, { anchorEl: anchorEl, open: Boolean(anchorEl), anchorOrigin: { vertical: 'top', horizontal: 'left', }, transformOrigin: { vertical: 'top', horizontal: 'left', }, onClose: handleClose }, (threadActions?.length && thread) ? threadActions.map((ActionComponent, index) => (React.createElement(ActionComponent, { key: index, thread: thread.data, onClose: handleClose }))) : (React.createElement(slots.baseMenuItem, { startIcon: DeleteIcon, onClick: handleDelete }, locale.threadActionDelete)))); }; export default ThreadListItemMenu;