import { useCallback, useState, } from 'react' import { useTranslation } from 'react-i18next' import { useChatWithHistoryContext } from '../context' import List from './list' import AppIcon from '@/app/components/base/app-icon' import Button from '@/app/components/base/button' import { Edit05 } from '@/app/components/base/icons/src/vender/line/general' import type { ConversationItem } from '@/models/share' import Confirm from '@/app/components/base/confirm' import RenameModal from '@/app/components/base/chat/chat-with-history/sidebar/rename-modal' const Sidebar = () => { const { t } = useTranslation() const { appData, pinnedConversationList, conversationList, handleNewConversation, currentConversationId, handleChangeConversation, handlePinConversation, handleUnpinConversation, conversationRenaming, handleRenameConversation, handleDeleteConversation, isMobile, } = useChatWithHistoryContext() const [showConfirm, setShowConfirm] = useState(null) const [showRename, setShowRename] = useState(null) const handleOperate = useCallback((type: string, item: ConversationItem) => { if (type === 'pin') handlePinConversation(item.id) if (type === 'unpin') handleUnpinConversation(item.id) if (type === 'delete') setShowConfirm(item) if (type === 'rename') setShowRename(item) }, [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 (
{ !isMobile && (
{appData?.site.title}
) }
{ !!pinnedConversationList.length && (
) } { !!conversationList.length && ( ) }
© {appData?.site.copyright || appData?.site.title} {(new Date()).getFullYear()}
{!!showConfirm && ( )} {showRename && ( )}
) } export default Sidebar