import classNames from '~/lib/classNames' import StyledButton from '../StyledButton' import { router, usePage } from '@inertiajs/react' import { ChatSession } from '../../../types/chat' import { IconMessage } from '@tabler/icons-react' import { useState } from 'react' import { useTranslation } from 'react-i18next' import KnowledgeBaseModal from './KnowledgeBaseModal' interface ChatSidebarProps { sessions: ChatSession[] activeSessionId: string | null onSessionSelect: (id: string) => void onNewChat: () => void onClearHistory: () => void isInModal?: boolean } export default function ChatSidebar({ sessions, activeSessionId, onSessionSelect, onNewChat, onClearHistory, isInModal = false, }: ChatSidebarProps) { const { t } = useTranslation() const { aiAssistantName } = usePage<{ aiAssistantName: string }>().props const [isKnowledgeBaseModalOpen, setIsKnowledgeBaseModalOpen] = useState( () => new URLSearchParams(window.location.search).get('knowledge_base') === 'true' ) function handleCloseKnowledgeBase() { setIsKnowledgeBaseModalOpen(false) const params = new URLSearchParams(window.location.search) if (params.has('knowledge_base')) { params.delete('knowledge_base') const newUrl = [window.location.pathname, params.toString()].filter(Boolean).join('?') window.history.replaceState(window.history.state, '', newUrl) } } return (
{t('chat.newChat')}
{sessions.length === 0 ? (
{t('chat.noPreviousChats')}
) : (
{sessions.map((session) => ( ))}
)}
Project Nomad Logo { if (isInModal) { window.open('/chat', '_blank') } else { router.visit('/home') } }} icon={isInModal ? 'IconExternalLink' : 'IconHome'} variant="outline" size="sm" fullWidth > {isInModal ? t('chat.openInNewTab') : t('common.backToHome')} { router.visit('/settings/models') }} icon="IconDatabase" variant="primary" size="sm" fullWidth > {t('chat.modelsAndSettings')} { setIsKnowledgeBaseModalOpen(true) }} icon="IconBrain" variant="primary" size="sm" fullWidth > {t('chat.knowledgeBase')} {sessions.length > 0 && ( {t('chat.clearHistory')} )}
{isKnowledgeBaseModalOpen && ( )}
) }