import { useCallback, useMemo } from 'react'; import { Tooltip, TooltipContent, TooltipTrigger } from '@renderer/components/ui/tooltip'; import { useStore } from '@renderer/store'; import { resolveProjectIdByPath } from '@renderer/utils/projectLookup'; import { formatSessionLabel } from '@renderer/utils/sessionTitleParser'; import { formatDistanceToNowStrict } from 'date-fns'; import { AlertCircle, Crown, ExternalLink, Filter, FilterX, Loader2, MessageSquare, Monitor, } from 'lucide-react'; import { useShallow } from 'zustand/react/shallow'; import type { Session } from '@renderer/types/data'; interface TeamSessionsSectionProps { sessions: Session[]; sessionsLoading: boolean; sessionsError: string | null; leadSessionId?: string; selectedSessionId: string | null; onSelectSession: (sessionId: string | null) => void; projectPath?: string; } export const TeamSessionsSection = ({ sessions, sessionsLoading, sessionsError, leadSessionId, selectedSessionId, onSelectSession, projectPath, }: TeamSessionsSectionProps): React.JSX.Element => { const { openTab, selectSession, projects, repositoryGroups } = useStore( useShallow((s) => ({ openTab: s.openTab, selectSession: s.selectSession, projects: s.projects, repositoryGroups: s.repositoryGroups, })) ); const projectId = useMemo( () => resolveProjectIdByPath(projectPath, projects, repositoryGroups), [projects, repositoryGroups, projectPath] ); // Sort: lead session first, then by most recent const sortedSessions = useMemo(() => { if (!leadSessionId) return sessions; return [...sessions].sort((a, b) => { if (a.id === leadSessionId) return -1; if (b.id === leadSessionId) return 1; return b.createdAt - a.createdAt; }); }, [sessions, leadSessionId]); const handleSessionClick = useCallback( (session: Session) => { if (!projectId) return; openTab( { type: 'session', sessionId: session.id, projectId, label: formatSessionLabel(session.firstMessage), }, { forceNewTab: true } ); selectSession(session.id); }, [projectId, openTab, selectSession] ); if (!projectPath) { return (
Sessions will appear after team provisioning
{projectPath}