import React, { useMemo, useState } from 'react'; import { Box, Button, Flex, useTheme, Menu, MenuButton, MenuList, MenuItem, IconButton } from '@chakra-ui/react'; import { useGlobalStore } from '@/store/global'; import { useEditInfo } from '@/hooks/useEditInfo'; import { useRouter } from 'next/router'; import Avatar from '@/components/Avatar'; import MyTooltip from '@/components/MyTooltip'; import MyIcon from '@/components/Icon'; type HistoryItemType = { id: string; title: string; customTitle?: string; top?: boolean; }; const ChatHistorySlider = ({ appId, appName, appAvatar, history, activeChatId, onChangeChat, onDelHistory, onSetHistoryTop, onSetCustomTitle }: { appId?: string; appName: string; appAvatar: string; history: HistoryItemType[]; activeChatId: string; onChangeChat: (chatId?: string) => void; onDelHistory: (chatId: string) => void; onSetHistoryTop?: (e: { chatId: string; top: boolean }) => void; onSetCustomTitle?: (e: { chatId: string; title: string }) => void; }) => { const theme = useTheme(); const router = useRouter(); const { isPc } = useGlobalStore(); // custom title edit const { onOpenModal, EditModal: EditTitleModal } = useEditInfo({ title: '自定义历史记录标题', placeholder: '如果设置为空,会自动跟随聊天记录。' }); const concatHistory = useMemo( () => (!activeChatId ? [{ id: activeChatId, title: '新对话' }].concat(history) : history), [activeChatId, history] ); return ( {isPc && ( appId && router.push({ pathname: '/app/detail', query: { appId } }) } > {appName} )} {/* 新对话 */} {/* chat history */} {concatHistory.map((item) => ( { onChangeChat(item.id); } })} > {item.customTitle || item.title} {!!item.id && ( { e.stopPropagation(); }} > {onSetHistoryTop && ( { e.stopPropagation(); onSetHistoryTop({ chatId: item.id, top: !item.top }); }} > {item.top ? '取消置顶' : '置顶'} )} {onSetCustomTitle && ( { e.stopPropagation(); onOpenModal({ defaultVal: item.customTitle || item.title, onSuccess: (e) => onSetCustomTitle({ chatId: item.id, title: e }) }); }} > 自定义标题 )} { e.stopPropagation(); onDelHistory(item.id); if (item.id === activeChatId) { onChangeChat(); } }} > 删除 )} ))} {!isPc && appId && ( router.push('/app/list')} > } bg={'white'} boxShadow={'1px 1px 9px rgba(0,0,0,0.15)'} h={'28px'} size={'sm'} borderRadius={'50%'} aria-label={''} /> 切换应用 )} ); }; export default ChatHistorySlider;