import { useCallback, useState, } from 'react' import { useTranslation } from 'react-i18next' import { RiEditBoxLine, RiExpandRightLine, RiLayoutLeft2Line, } from '@remixicon/react' import { useChatWithHistoryContext } from '../context' import AppIcon from '@/app/components/base/app-icon' import ActionButton from '@/app/components/base/action-button' import Button from '@/app/components/base/button' import List from '@/app/components/base/chat/chat-with-history/sidebar/list' import MenuDropdown from '@/app/components/share/text-generation/menu-dropdown' import Confirm from '@/app/components/base/confirm' import RenameModal from '@/app/components/base/chat/chat-with-history/sidebar/rename-modal' import LogoSite from '@/app/components/base/logo/logo-site' import type { ConversationItem } from '@/models/share' import cn from '@/utils/classnames' type Props = { isPanel?: boolean } const Sidebar = ({ isPanel }: Props) => { const { t } = useTranslation() const { appData, handleNewConversation, pinnedConversationList, conversationList, currentConversationId, handleChangeConversation, handlePinConversation, handleUnpinConversation, conversationRenaming, handleRenameConversation, handleDeleteConversation, sidebarCollapseState, handleSidebarCollapse, isMobile, isResponding, } = useChatWithHistoryContext() const isSidebarCollapsed = sidebarCollapseState 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 (
{appData?.site.title}
{!isMobile && isSidebarCollapsed && ( handleSidebarCollapse(false)}> )} {!isMobile && !isSidebarCollapsed && ( handleSidebarCollapse(true)}> )}
{/* pinned list */} {!!pinnedConversationList.length && (
)} {!!conversationList.length && ( )}
{/* powered by */}
{!appData?.custom_config?.remove_webapp_brand && (
{t('share.chat.poweredBy')}
{appData?.custom_config?.replace_webapp_logo && ( logo )} {!appData?.custom_config?.replace_webapp_logo && ( )}
)}
{!!showConfirm && ( )} {showRename && ( )}
) } export default Sidebar