import { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiMenuLine, } from '@remixicon/react' import { useChatWithHistoryContext } from './context' import Operation from './header/operation' import Sidebar from './sidebar' import MobileOperationDropdown from './header/mobile-operation-dropdown' import AppIcon from '@/app/components/base/app-icon' import ActionButton from '@/app/components/base/action-button' import { Message3Fill } from '@/app/components/base/icons/src/public/other' import InputsFormContent from '@/app/components/base/chat/chat-with-history/inputs-form/content' 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' const HeaderInMobile = () => { const { appData, currentConversationId, currentConversationItem, pinnedConversationList, handleNewConversation, handlePinConversation, handleUnpinConversation, handleDeleteConversation, handleRenameConversation, conversationRenaming, } = useChatWithHistoryContext() const { t } = useTranslation() 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]) const [showSidebar, setShowSidebar] = useState(false) const [showChatSettings, setShowChatSettings] = useState(false) return ( <>
setShowSidebar(true)}>
{!currentConversationId && ( <>
{appData?.site.title}
)} {currentConversationId && ( handleOperate(isPin ? 'unpin' : 'pin')} isShowDelete isShowRenameConversation onRenameConversation={() => handleOperate('rename')} onDelete={() => handleOperate('delete')} /> )}
setShowChatSettings(true)} />
{showSidebar && (
setShowSidebar(false)} >
e.stopPropagation()}>
)} {showChatSettings && (
setShowChatSettings(false)} >
e.stopPropagation()}>
{t('share.chat.chatSettingsTitle')}
)} {!!showConfirm && ( )} {showRename && ( )} ) } export default HeaderInMobile