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

55 lines (54 loc) 2.59 kB
import * as React from 'react'; import { DeleteIcon, EditIcon, PushPinIcon } 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, enableDialogueRename, enableThreadPin, onPinThread } = useHistoryContext(); const menuConfig = model.listGroups.menuConfig; const config = useObserverValue(menuConfig); const pinnedAt = useObserverValue(config?.thread?.pinnedAt); 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; } }; const handleRename = () => { handleClose(); if (thread && internal) { internal.model.renameItem.value = thread.data; } }; const handlePin = () => { handleClose(); if (thread) { const nextPinnedAt = pinnedAt ? null : Date.now(); thread.pinnedAt.value = nextPinnedAt; onPinThread?.(thread.id, nextPinnedAt); model.listGroups.audit(locale, model.list.value); } }; return (React.createElement(MdMenu, { anchorEl: anchorEl, open: Boolean(anchorEl), anchorOrigin: { vertical: 'top', horizontal: 'left', }, transformOrigin: { vertical: 'top', horizontal: 'left', }, onClose: handleClose }, enableDialogueRename ? (React.createElement(slots.baseMenuItem, { startIcon: EditIcon, onClick: handleRename }, locale.threadActionRename)) : null, enableThreadPin ? (React.createElement(slots.baseMenuItem, { startIcon: PushPinIcon, onClick: handlePin }, pinnedAt ? locale.threadActionUnpin : locale.threadActionPin)) : null, (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;