-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectTabBar.tsx
More file actions
130 lines (118 loc) · 3.9 KB
/
Copy pathProjectTabBar.tsx
File metadata and controls
130 lines (118 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { Plus } from 'lucide-react';
import { cn } from '../lib/utils';
import { Button } from './ui/button';
import { SortableProjectTab } from './SortableProjectTab';
import { UsageIndicator } from './UsageIndicator';
import { AuthStatusIndicator } from './AuthStatusIndicator';
import type { Project } from '../../shared/types';
interface ProjectTabBarProps {
projects: Project[];
activeProjectId: string | null;
onProjectSelect: (projectId: string) => void;
onProjectClose: (projectId: string) => void;
onAddProject: () => void;
className?: string;
// Control props for active tab
onSettingsClick?: () => void;
}
export function ProjectTabBar({
projects,
activeProjectId,
onProjectSelect,
onProjectClose,
onAddProject,
className,
onSettingsClick
}: ProjectTabBarProps) {
const { t } = useTranslation('common');
// Keyboard shortcuts for tab navigation
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
// Skip if in input fields
if (
e.target instanceof HTMLInputElement ||
e.target instanceof HTMLTextAreaElement ||
(e.target as HTMLElement)?.isContentEditable
) {
return;
}
const isMod = e.metaKey || e.ctrlKey;
if (!isMod) return;
// Cmd/Ctrl + 1-9: Switch to tab N
if (e.key >= '1' && e.key <= '9') {
e.preventDefault();
const index = parseInt(e.key, 10) - 1;
if (index < projects.length) {
onProjectSelect(projects[index].id);
}
return;
}
// Cmd/Ctrl + Tab: Next tab
// Cmd/Ctrl + Shift + Tab: Previous tab
if (e.key === 'Tab') {
e.preventDefault();
const currentIndex = projects.findIndex((p) => p.id === activeProjectId);
if (currentIndex === -1 || projects.length === 0) return;
const nextIndex = e.shiftKey
? (currentIndex - 1 + projects.length) % projects.length
: (currentIndex + 1) % projects.length;
onProjectSelect(projects[nextIndex].id);
return;
}
// Cmd/Ctrl + W: Close current tab (only if more than one tab)
if (e.key === 'w' && activeProjectId && projects.length > 1) {
e.preventDefault();
onProjectClose(activeProjectId);
}
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, [projects, activeProjectId, onProjectSelect, onProjectClose]);
if (projects.length === 0) {
return null;
}
return (
<div className={cn(
'flex items-center border-b border-border bg-background',
'overflow-x-auto scrollbar-thin scrollbar-thumb-border scrollbar-track-transparent',
className
)}>
<div className="flex items-center flex-1 min-w-0">
{projects.map((project, index) => {
const isActiveTab = activeProjectId === project.id;
return (
<SortableProjectTab
key={project.id}
project={project}
isActive={isActiveTab}
canClose={projects.length > 1}
tabIndex={index}
onSelect={() => onProjectSelect(project.id)}
onClose={(e) => {
e.stopPropagation();
onProjectClose(project.id);
}}
// Pass control props only for active tab
onSettingsClick={isActiveTab ? onSettingsClick : undefined}
/>
);
})}
</div>
<div className="flex items-center gap-2 px-2 py-1">
<AuthStatusIndicator />
<UsageIndicator />
<Button
variant="ghost"
size="icon"
className="h-8 w-8"
onClick={onAddProject}
aria-label={t('projectTab.addProjectAriaLabel')}
>
<Plus className="h-4 w-4" />
</Button>
</div>
</div>
);
}