import React from 'react'; import { RiArrowDownSLine, RiArrowRightSLine } from '@remixicon/react'; import { cn } from '@/lib/utils'; import type { SessionNode } from './types'; import { useI18n } from '@/lib/i18n'; type ActivityItem = { node: SessionNode; projectId: string | null; groupDirectory: string | null; secondaryMeta: { projectLabel?: string | null; branchLabel?: string | null; } | null; }; type ActivitySection = { key: 'active-now'; title: string; items: ActivityItem[]; }; type Props = { sections: ActivitySection[]; renderSessionNode: (node: SessionNode, depth?: number, groupDirectory?: string | null, projectId?: string | null, archivedBucket?: boolean, secondaryMeta?: { projectLabel?: string | null; branchLabel?: string | null } | null, renderContext?: 'project' | 'recent') => React.ReactNode; }; const MAX_VISIBLE_RECENT_SESSIONS = 7; export function SidebarActivitySections({ sections, renderSessionNode }: Props): React.ReactNode { const { t } = useI18n(); const [collapsed, setCollapsed] = React.useState>(new Set()); const [expandedSections, setExpandedSections] = React.useState>(new Set()); const toggleSection = React.useCallback((key: string) => { setCollapsed((prev) => { const next = new Set(prev); if (next.has(key)) { next.delete(key); } else { next.add(key); } return next; }); }, []); const toggleSectionLimit = React.useCallback((key: string) => { setExpandedSections((prev) => { const next = new Set(prev); if (next.has(key)) { next.delete(key); } else { next.add(key); } return next; }); }, []); const visibleSections = sections.filter((section) => section.items.length > 0); if (visibleSections.length === 0) { return null; } return (
{visibleSections.map((section) => { const isCollapsed = collapsed.has(section.key); const isExpanded = expandedSections.has(section.key); const visibleItems = isExpanded ? section.items : section.items.slice(0, MAX_VISIBLE_RECENT_SESSIONS); const remainingCount = section.items.length - visibleItems.length; return (
{!isCollapsed ? (
{visibleItems.map((item) => renderSessionNode(item.node, 0, item.groupDirectory, item.projectId, false, item.secondaryMeta, 'recent'))} {remainingCount > 0 && !isExpanded ? ( ) : null} {isExpanded && section.items.length > MAX_VISIBLE_RECENT_SESSIONS ? ( ) : null}
) : null}
); })}
); }