forked from op7418/CodePilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavRail.tsx
More file actions
161 lines (153 loc) · 5.83 KB
/
NavRail.tsx
File metadata and controls
161 lines (153 loc) · 5.83 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"use client";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import {
ChatCircle,
Lightning,
Plug,
Image,
Gear,
WifiHigh,
Terminal,
} 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 type { TranslationKey } from "@/i18n";
interface NavRailProps {
chatListOpen: boolean;
onToggleChatList: () => void;
hasUpdate?: boolean;
readyToInstall?: boolean;
skipPermissionsActive?: boolean;
}
const navItems = [
{ href: "/chat", label: "Chats", icon: ChatCircle },
{ href: "/skills", label: "Skills", icon: Lightning },
{ href: "/mcp", label: "MCP", icon: Plug },
{ href: "/cli-tools", label: "CLI Tools", icon: Terminal },
{ href: "/gallery", label: "Gallery", icon: Image },
{ href: "/bridge", label: "Bridge", icon: WifiHigh },
] as const;
export function NavRail({ onToggleChatList, hasUpdate, readyToInstall, skipPermissionsActive }: NavRailProps) {
const pathname = usePathname();
const router = useRouter();
const { t } = useTranslation();
const navLabelKeys: Record<string, TranslationKey> = {
'Chats': 'nav.chats',
'Skills': 'extensions.skills',
'MCP': 'extensions.mcpServers',
'Gallery': 'gallery.title',
'Bridge': 'nav.bridge',
'CLI Tools': 'nav.cliTools',
};
const isChatRoute = pathname === "/chat" || pathname.startsWith("/chat/");
const isSettingsActive = pathname === "/settings" || pathname.startsWith("/settings/");
return (
<aside className="flex w-14 shrink-0 flex-col items-center bg-sidebar/80 backdrop-blur-xl pb-3 pt-10">
{/* Nav icons */}
<nav className="flex flex-1 flex-col items-center gap-1">
{navItems.map((item) => {
const isActive =
item.href === "/chat"
? pathname === "/chat" || pathname.startsWith("/chat/")
: pathname === item.href || pathname.startsWith(item.href + "/") || pathname.startsWith(item.href + "?");
return (
<Tooltip key={item.href}>
<TooltipTrigger asChild>
{item.href === "/chat" ? (
<Button
variant="ghost"
size="icon"
className={cn(
"h-9 w-9",
isActive && "bg-sidebar-accent text-sidebar-accent-foreground"
)}
onClick={() => {
if (!isChatRoute) {
// Navigate to chat page first, then open chat list
router.push("/chat");
onToggleChatList();
} else {
onToggleChatList();
}
}}
>
<item.icon size={16} weight={isActive ? "fill" : "regular"} />
<span className="sr-only">{t(navLabelKeys[item.label] ?? item.label as TranslationKey)}</span>
</Button>
) : (
<div className="relative">
<Button
asChild
variant="ghost"
size="icon"
className={cn(
"h-9 w-9",
isActive && "bg-sidebar-accent text-sidebar-accent-foreground"
)}
>
<Link href={item.href}>
<item.icon size={16} weight={isActive ? "fill" : "regular"} />
<span className="sr-only">{t(navLabelKeys[item.label] ?? item.label as TranslationKey)}</span>
</Link>
</Button>
</div>
)}
</TooltipTrigger>
<TooltipContent side="right">{t(navLabelKeys[item.label] ?? item.label as TranslationKey)}</TooltipContent>
</Tooltip>
);
})}
</nav>
{/* Bottom: skip-permissions indicator + settings */}
<div className="mt-auto flex flex-col items-center gap-2">
{skipPermissionsActive && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex h-8 w-8 items-center justify-center">
<span className="relative flex h-3 w-3">
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-status-warning opacity-75" />
<span className="relative inline-flex h-3 w-3 rounded-full bg-status-warning" />
</span>
</div>
</TooltipTrigger>
<TooltipContent side="right">{t('nav.autoApproveOn')}</TooltipContent>
</Tooltip>
)}
<Tooltip>
<TooltipTrigger asChild>
<div className="relative">
<Button
asChild
variant="ghost"
size="icon"
className={cn(
"h-9 w-9",
isSettingsActive && "bg-sidebar-accent text-sidebar-accent-foreground"
)}
>
<Link href="/settings">
<Gear size={16} weight={isSettingsActive ? "fill" : "regular"} />
<span className="sr-only">{t('nav.settings')}</span>
</Link>
</Button>
{hasUpdate && (
<span className={cn(
"absolute top-0.5 right-0.5 h-2 w-2 rounded-full",
readyToInstall ? "bg-status-success animate-pulse" : "bg-primary"
)} />
)}
</div>
</TooltipTrigger>
<TooltipContent side="right">{t('nav.settings')}</TooltipContent>
</Tooltip>
</div>
</aside>
);
}