project-nomad/admin/inertia/components/chat/ChatSidebar.tsx
Martin Seener 134d1642af
Added initial i18n framework and most german translations
- Add i18next, react-i18next, i18next-browser-languagedetector packages
- Configure i18n initialization with language detector in lib/i18n.ts
- Created en/de translation files and moved most hard-coded strings into the files and translated them
- Uses locale-aware date formatting where applicable
- Added language-specific Wikipedia content files (wikipedia.en.json, wikipedia.de.json) and updated download URLs
- Added NOMAD_REPO_URL env variable for fork-friendly URL resolution (easier testing and rollout independent of Crosstalk repo)
2026-03-24 13:21:31 +01:00

150 lines
5.0 KiB
TypeScript

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 (
<div className="w-64 bg-surface-secondary border-r border-border-subtle flex flex-col h-full">
<div className="p-4 border-b border-border-subtle h-[75px] flex items-center justify-center">
<StyledButton onClick={onNewChat} icon="IconPlus" variant="primary" fullWidth>
{t('chat.newChat')}
</StyledButton>
</div>
<div className="flex-1 overflow-y-auto">
{sessions.length === 0 ? (
<div className="p-4 text-center text-text-muted text-sm">{t('chat.noPreviousChats')}</div>
) : (
<div className="p-2 space-y-1">
{sessions.map((session) => (
<button
key={session.id}
onClick={() => onSessionSelect(session.id)}
className={classNames(
'w-full text-left px-3 py-2 rounded-lg transition-colors group',
activeSessionId === session.id
? 'bg-desert-green text-white'
: 'hover:bg-surface-secondary text-text-primary'
)}
>
<div className="flex items-start gap-2">
<IconMessage
className={classNames(
'h-5 w-5 mt-0.5 shrink-0',
activeSessionId === session.id ? 'text-white' : 'text-text-muted'
)}
/>
<div className="flex-1 min-w-0">
<div className="font-medium text-sm truncate">{session.title}</div>
{session.lastMessage && (
<div
className={classNames(
'text-xs truncate mt-0.5',
activeSessionId === session.id ? 'text-white/80' : 'text-text-muted'
)}
>
{session.lastMessage}
</div>
)}
</div>
</div>
</button>
))}
</div>
)}
</div>
<div className="p-4 flex flex-col items-center justify-center gap-y-2">
<img src="/project_nomad_logo.png" alt="Project Nomad Logo" className="h-28 w-28 mb-6" />
<StyledButton
onClick={() => {
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')}
</StyledButton>
<StyledButton
onClick={() => {
router.visit('/settings/models')
}}
icon="IconDatabase"
variant="primary"
size="sm"
fullWidth
>
{t('chat.modelsAndSettings')}
</StyledButton>
<StyledButton
onClick={() => {
setIsKnowledgeBaseModalOpen(true)
}}
icon="IconBrain"
variant="primary"
size="sm"
fullWidth
>
{t('chat.knowledgeBase')}
</StyledButton>
{sessions.length > 0 && (
<StyledButton
onClick={onClearHistory}
icon="IconTrash"
variant="danger"
size="sm"
fullWidth
>
{t('chat.clearHistory')}
</StyledButton>
)}
</div>
{isKnowledgeBaseModalOpen && (
<KnowledgeBaseModal aiAssistantName={aiAssistantName} onClose={handleCloseKnowledgeBase} />
)}
</div>
)
}