forked from op7418/CodePilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectGroupHeader.tsx
More file actions
122 lines (118 loc) · 3.9 KB
/
ProjectGroupHeader.tsx
File metadata and controls
122 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
"use client";
import {
Folder,
CaretDown,
CaretRight,
Plus,
FolderOpen,
UserCircle,
} from "@/components/ui/icon";
import { Button } from "@/components/ui/button";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
import { useTranslation } from '@/hooks/useTranslation';
import { useClientPlatform } from '@/hooks/useClientPlatform';
interface ProjectGroupHeaderProps {
workingDirectory: string;
displayName: string;
isCollapsed: boolean;
isFolderHovered: boolean;
isWorkspace: boolean;
onToggle: () => void;
onMouseEnter: () => void;
onMouseLeave: () => void;
onCreateSession: (e: React.MouseEvent) => void;
}
export function ProjectGroupHeader({
workingDirectory,
displayName,
isCollapsed,
isFolderHovered,
isWorkspace,
onToggle,
onMouseEnter,
onMouseLeave,
onCreateSession,
}: ProjectGroupHeaderProps) {
const { t } = useTranslation();
const { fileManagerName } = useClientPlatform();
return (
<Tooltip>
<TooltipTrigger asChild>
<div
className={cn(
"flex items-center gap-1 rounded-md px-2 py-1 cursor-pointer select-none transition-colors",
"hover:bg-accent/50"
)}
onClick={onToggle}
onDoubleClick={(e) => {
e.stopPropagation();
if (workingDirectory) {
if (window.electronAPI?.shell?.openPath) {
window.electronAPI.shell.openPath(workingDirectory);
} else {
fetch('/api/files/open', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path: workingDirectory }),
}).catch(() => {});
}
}
}}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
{isCollapsed ? (
<CaretRight size={14} className="shrink-0 text-muted-foreground" />
) : (
<CaretDown size={14} className="shrink-0 text-muted-foreground" />
)}
{isCollapsed ? (
<Folder size={16} className="shrink-0 text-muted-foreground" />
) : (
<FolderOpen size={16} className="shrink-0 text-muted-foreground" />
)}
<span className="flex-1 truncate text-[13px] font-medium text-sidebar-foreground">
{displayName}
</span>
{isWorkspace && (
<UserCircle size={14} className="shrink-0 text-muted-foreground" />
)}
{/* New chat in project button (on hover) */}
{workingDirectory !== "" && (
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon-xs"
className={cn(
"h-5 w-5 shrink-0 text-muted-foreground hover:text-foreground transition-opacity",
isFolderHovered ? "opacity-100" : "opacity-0"
)}
tabIndex={isFolderHovered ? 0 : -1}
onClick={onCreateSession}
>
<Plus size={14} />
<span className="sr-only">
{t('chatList.newConversation')} - {displayName}
</span>
</Button>
</TooltipTrigger>
<TooltipContent side="right">
{t('chatList.newConversation')} - {displayName}
</TooltipContent>
</Tooltip>
)}
</div>
</TooltipTrigger>
<TooltipContent side="right" className="max-w-xs">
<p className="text-xs break-all">{workingDirectory || t('chatList.noSessions')}</p>
{workingDirectory && <p className="text-[10px] text-muted-foreground mt-0.5">{t('platform.openInFileManager', { fileManager: fileManagerName })}</p>}
</TooltipContent>
</Tooltip>
);
}