/** * SessionSidebar.jsx - Chat History Sidebar */ const { useState } = React; function SessionSidebar({ sessions, activeSessionId, onSelectSession, onNewChat, onDeleteSession, onRenameSession, t }) { return (
{/* Header */}

💬 {t('ask.history') || 'Chat History'}

{/* New Chat Button */}
{/* Sessions List */}
{sessions.length === 0 ? (
💬

{t('ask.noSessions')}

) : ( sessions.map(session => ( onSelectSession(session.id)} onDelete={(e) => onDeleteSession(session.id, e)} onRename={onRenameSession} /> )) )}
); } function SessionCard({ session, isActive, onClick, onDelete, onRename }) { const [isHovered, setIsHovered] = useState(false); const [isEditing, setIsEditing] = useState(false); const [editTitle, setEditTitle] = useState(session.title); const handleDelete = async (e, sessionId) => { e.stopPropagation(); // Prevent triggering session selection if (onDelete) { // Changed onDeleteSession to onDelete as per prop await onDelete(e); // Pass the event directly to the onDelete prop } }; const handleRename = async (e) => { e.stopPropagation(); if (!editTitle.trim() || editTitle === session.title) { setIsEditing(false); setEditTitle(session.title); return; } try { const token = localStorage.getItem('token'); const response = await fetch(`${API_URL}/ask/sessions/${session.id}/rename?new_title=${encodeURIComponent(editTitle)}`, { method: 'PUT', headers: { 'Authorization': `Bearer ${token}` } }); if (response.ok) { onRename(session.id, editTitle); setIsEditing(false); } } catch (error) { console.error('Failed to rename:', error); setEditTitle(session.title); setIsEditing(false); } }; return (
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} style={{ padding: '0.75rem 1rem', margin: '0.5rem 0', borderRadius: '12px', cursor: 'pointer', background: isActive ? 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)' : isHovered ? 'rgba(102, 126, 234, 0.08)' : 'transparent', border: `1px solid ${isActive ? 'transparent' : 'var(--border-color, rgba(0,0,0,0.06))'}`, transition: 'all 0.2s ease', position: 'relative', color: isActive ? 'white' : 'var(--text-primary, #1e293b)' }} > {isEditing ? ( setEditTitle(e.target.value)} onBlur={handleRename} onKeyDown={(e) => { if (e.key === 'Enter') handleRename(e); if (e.key === 'Escape') { setIsEditing(false); setEditTitle(session.title); } e.stopPropagation(); }} onClick={(e) => e.stopPropagation()} autoFocus style={{ width: '100%', padding: '0.25rem', background: 'white', border: '2px solid #667eea', borderRadius: '6px', fontSize: '0.875rem', fontWeight: '600', color: '#1e293b', outline: 'none' }} /> ) : (
{session.title}
{session.last_message_preview && (
{session.last_message_preview}
)}
{isHovered && !isActive && (
)}
)}
); } window.SessionSidebar = SessionSidebar;