-
Notifications
You must be signed in to change notification settings - Fork 993
Expand file tree
/
Copy pathSidebar.tsx
More file actions
141 lines (133 loc) · 3.87 KB
/
Sidebar.tsx
File metadata and controls
141 lines (133 loc) · 3.87 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
/**
* Sidebar Component
* Navigation sidebar with menu items.
* No longer fixed - sits inside the flex layout below the title bar.
*/
import { NavLink } from 'react-router-dom';
import {
Home,
MessageSquare,
Radio,
Puzzle,
Clock,
Settings,
ChevronLeft,
ChevronRight,
Terminal,
ExternalLink,
} from 'lucide-react';
import { cn } from '@/lib/utils';
import { useSettingsStore } from '@/stores/settings';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
interface NavItemProps {
to: string;
icon: React.ReactNode;
label: string;
badge?: string;
collapsed?: boolean;
}
function NavItem({ to, icon, label, badge, collapsed }: NavItemProps) {
return (
<NavLink
to={to}
className={({ isActive }) =>
cn(
'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors',
'hover:bg-accent hover:text-accent-foreground',
isActive
? 'bg-accent text-accent-foreground'
: 'text-muted-foreground',
collapsed && 'justify-center px-2'
)
}
>
{icon}
{!collapsed && (
<>
<span className="flex-1">{label}</span>
{badge && (
<Badge variant="secondary" className="ml-auto">
{badge}
</Badge>
)}
</>
)}
</NavLink>
);
}
export function Sidebar() {
const sidebarCollapsed = useSettingsStore((state) => state.sidebarCollapsed);
const setSidebarCollapsed = useSettingsStore((state) => state.setSidebarCollapsed);
const devModeUnlocked = useSettingsStore((state) => state.devModeUnlocked);
const openDevConsole = async () => {
try {
const result = await window.electron.ipcRenderer.invoke('gateway:getControlUiUrl') as {
success: boolean;
url?: string;
error?: string;
};
if (result.success && result.url) {
window.electron.openExternal(result.url);
} else {
console.error('Failed to get Dev Console URL:', result.error);
}
} catch (err) {
console.error('Error opening Dev Console:', err);
}
};
const navItems = [
{ to: '/', icon: <MessageSquare className="h-5 w-5" />, label: 'Chat' },
{ to: '/cron', icon: <Clock className="h-5 w-5" />, label: 'Cron Tasks' },
{ to: '/skills', icon: <Puzzle className="h-5 w-5" />, label: 'Skills' },
{ to: '/channels', icon: <Radio className="h-5 w-5" />, label: 'Channels' },
{ to: '/dashboard', icon: <Home className="h-5 w-5" />, label: 'Dashboard' },
{ to: '/settings', icon: <Settings className="h-5 w-5" />, label: 'Settings' },
];
return (
<aside
className={cn(
'flex shrink-0 flex-col border-r bg-background transition-all duration-300',
sidebarCollapsed ? 'w-16' : 'w-64'
)}
>
{/* Navigation */}
<nav className="flex-1 space-y-1 overflow-auto p-2">
{navItems.map((item) => (
<NavItem
key={item.to}
{...item}
collapsed={sidebarCollapsed}
/>
))}
</nav>
{/* Footer */}
<div className="p-2 space-y-2">
{devModeUnlocked && !sidebarCollapsed && (
<Button
variant="ghost"
size="sm"
className="w-full justify-start"
onClick={openDevConsole}
>
<Terminal className="h-4 w-4 mr-2" />
Developer Console
<ExternalLink className="h-3 w-3 ml-auto" />
</Button>
)}
<Button
variant="ghost"
size="icon"
className="w-full"
onClick={() => setSidebarCollapsed(!sidebarCollapsed)}
>
{sidebarCollapsed ? (
<ChevronRight className="h-4 w-4" />
) : (
<ChevronLeft className="h-4 w-4" />
)}
</Button>
</div>
</aside>
);
}