import { Button } from '../../../ui/button'; import { Check, ChevronDown, ChevronRight, Edit3, Folder, FolderOpen, Star, Trash2, X } from 'lucide-react'; import type { TFunction } from 'i18next'; import { cn } from '../../../../lib/utils'; import TaskIndicator from '../../../TaskIndicator'; import type { Project, ProjectSession, SessionProvider } from '../../../../types/app'; import type { MCPServerStatus, SessionWithProvider, TouchHandlerFactory } from '../../types/types'; import { getTaskIndicatorStatus } from '../../utils/utils'; import SidebarProjectSessions from './SidebarProjectSessions'; type SidebarProjectItemProps = { project: Project; selectedProject: Project | null; selectedSession: ProjectSession | null; isExpanded: boolean; isDeleting: boolean; isStarred: boolean; editingProject: string | null; editingName: string; sessions: SessionWithProvider[]; initialSessionsLoaded: boolean; isLoadingSessions: boolean; currentTime: Date; editingSession: string | null; editingSessionName: string; tasksEnabled: boolean; mcpServerStatus: MCPServerStatus; onEditingNameChange: (name: string) => void; onToggleProject: (projectName: string) => void; onProjectSelect: (project: Project) => void; onToggleStarProject: (projectName: string) => void; onStartEditingProject: (project: Project) => void; onCancelEditingProject: () => void; onSaveProjectName: (projectName: string) => void; onDeleteProject: (project: Project) => void; onSessionSelect: (session: SessionWithProvider, projectName: string) => void; onDeleteSession: ( projectName: string, sessionId: string, sessionTitle: string, provider: SessionProvider, ) => void; onLoadMoreSessions: (project: Project) => void; onNewSession: (project: Project) => void; onEditingSessionNameChange: (value: string) => void; onStartEditingSession: (sessionId: string, initialName: string) => void; onCancelEditingSession: () => void; onSaveEditingSession: (projectName: string, sessionId: string, summary: string) => void; touchHandlerFactory: TouchHandlerFactory; t: TFunction; }; const getSessionCountDisplay = (sessions: SessionWithProvider[], hasMoreSessions: boolean): string => { const sessionCount = sessions.length; if (hasMoreSessions && sessionCount >= 5) { return `${sessionCount}+`; } return `${sessionCount}`; }; export default function SidebarProjectItem({ project, selectedProject, selectedSession, isExpanded, isDeleting, isStarred, editingProject, editingName, sessions, initialSessionsLoaded, isLoadingSessions, currentTime, editingSession, editingSessionName, tasksEnabled, mcpServerStatus, onEditingNameChange, onToggleProject, onProjectSelect, onToggleStarProject, onStartEditingProject, onCancelEditingProject, onSaveProjectName, onDeleteProject, onSessionSelect, onDeleteSession, onLoadMoreSessions, onNewSession, onEditingSessionNameChange, onStartEditingSession, onCancelEditingSession, onSaveEditingSession, touchHandlerFactory, t, }: SidebarProjectItemProps) { const isSelected = selectedProject?.name === project.name; const isEditing = editingProject === project.name; const hasMoreSessions = project.sessionMeta?.hasMore === true; const sessionCountDisplay = getSessionCountDisplay(sessions, hasMoreSessions); const sessionCountLabel = `${sessionCountDisplay} session${sessions.length === 1 ? '' : 's'}`; const taskStatus = getTaskIndicatorStatus(project, mcpServerStatus); const toggleProject = () => onToggleProject(project.name); const toggleStarProject = () => onToggleStarProject(project.name); const saveProjectName = () => { onSaveProjectName(project.name); }; const selectAndToggleProject = () => { if (selectedProject?.name !== project.name) { onProjectSelect(project); } toggleProject(); }; return (
{isExpanded ? ( ) : ( )}
{isEditing ? ( onEditingNameChange(event.target.value)} className="w-full px-3 py-2 text-sm border-2 border-primary/40 focus:border-primary rounded-lg bg-background text-foreground shadow-sm focus:shadow-md transition-all duration-200 focus:outline-none" placeholder={t('projects.projectNamePlaceholder')} autoFocus autoComplete="off" onClick={(event) => event.stopPropagation()} onKeyDown={(event) => { if (event.key === 'Enter') { saveProjectName(); } if (event.key === 'Escape') { onCancelEditingProject(); } }} style={{ fontSize: '16px', WebkitAppearance: 'none', borderRadius: '8px', }} /> ) : ( <>

{project.displayName}

{tasksEnabled && ( )}

{sessionCountLabel}

)}
{isEditing ? ( <> ) : ( <>
{isExpanded ? ( ) : ( )}
)}
); }