import { useCallback, useState } from 'react' import { RiEditBoxLine, RiLayoutRight2Line, RiResetLeftLine, } from '@remixicon/react' import { useTranslation } from 'react-i18next' import { useChatWithHistoryContext, } from '../context' import Operation from './operation' import ActionButton, { ActionButtonState } from '@/app/components/base/action-button' import AppIcon from '@/app/components/base/app-icon' import Tooltip from '@/app/components/base/tooltip' import ViewFormDropdown from '@/app/components/base/chat/chat-with-history/inputs-form/view-form-dropdown' import Confirm from '@/app/components/base/confirm' import RenameModal from '@/app/components/base/chat/chat-with-history/sidebar/rename-modal' import type { ConversationItem } from '@/models/share' import cn from '@/utils/classnames' const Header = () => { const { appData, currentConversationId, currentConversationItem, inputsForms, pinnedConversationList, handlePinConversation, handleUnpinConversation, conversationRenaming, handleRenameConversation, handleDeleteConversation, handleNewConversation, sidebarCollapseState, handleSidebarCollapse, isResponding, } = useChatWithHistoryContext() const { t } = useTranslation() const isSidebarCollapsed = sidebarCollapseState const isPin = pinnedConversationList.some(item => item.id === currentConversationId) const [showConfirm, setShowConfirm] = useState(null) const [showRename, setShowRename] = useState(null) const handleOperate = useCallback((type: string) => { if (type === 'pin') handlePinConversation(currentConversationId) if (type === 'unpin') handleUnpinConversation(currentConversationId) if (type === 'delete') setShowConfirm(currentConversationItem as any) if (type === 'rename') setShowRename(currentConversationItem as any) }, [currentConversationId, currentConversationItem, handlePinConversation, handleUnpinConversation]) const handleCancelConfirm = useCallback(() => { setShowConfirm(null) }, []) const handleDelete = useCallback(() => { if (showConfirm) handleDeleteConversation(showConfirm.id, { onSuccess: handleCancelConfirm }) }, [showConfirm, handleDeleteConversation, handleCancelConfirm]) const handleCancelRename = useCallback(() => { setShowRename(null) }, []) const handleRename = useCallback((newName: string) => { if (showRename) handleRenameConversation(showRename.id, newName, { onSuccess: handleCancelRename }) }, [showRename, handleRenameConversation, handleCancelRename]) return ( <>
handleSidebarCollapse(false)}>
{!currentConversationId && (
{appData?.site.title}
)} {currentConversationId && currentConversationItem && isSidebarCollapsed && ( <>
/
handleOperate(isPin ? 'unpin' : 'pin')} isShowDelete isShowRenameConversation onRenameConversation={() => handleOperate('rename')} onDelete={() => handleOperate('delete')} /> )}
{isSidebarCollapsed && (
)}
{currentConversationId && ( )} {currentConversationId && inputsForms.length > 0 && ( )}
{!!showConfirm && ( )} {showRename && ( )} ) } export default Header