import React, { useMemo } from 'react'; import { Box, Button, Flex, useTheme, Menu, MenuButton, MenuList, MenuItem } from '@chakra-ui/react'; import MyIcon from '@/components/Icon'; import { useGlobalStore } from '@/store/global'; import Avatar from '@/components/Avatar'; type HistoryItemType = { id: string; title: string; top?: boolean; }; const ChatHistorySlider = ({ appName, appAvatar, history, activeHistoryId, onChangeChat, onDelHistory, onSetHistoryTop, onCloseSlider }: { appName: string; appAvatar: string; history: HistoryItemType[]; activeHistoryId: string; onChangeChat: (historyId?: string) => void; onDelHistory: (historyId: string) => void; onSetHistoryTop?: (e: { historyId: string; top: boolean }) => void; onCloseSlider: () => void; }) => { const theme = useTheme(); const { isPc } = useGlobalStore(); const concatHistory = useMemo( () => (!activeHistoryId ? [{ id: activeHistoryId, title: '新对话' }].concat(history) : history), [activeHistoryId, history] ); return ( {isPc && ( {appName} )} {/* 新对话 */} {/* chat history */} {concatHistory.map((item) => ( { onChangeChat(item.id); } })} > {item.title} {!!item.id && ( { e.stopPropagation(); }} > {onSetHistoryTop && ( { e.stopPropagation(); onSetHistoryTop({ historyId: item.id, top: !item.top }); }} > {item.top ? '取消置顶' : '置顶'} )} { e.stopPropagation(); onDelHistory(item.id); if (item.id === activeHistoryId) { onChangeChat(); } }} > 删除 )} ))} ); }; export default ChatHistorySlider;