Files
opencode-manager/frontend/src/components/navigation/DesktopSidebar.tsx
T
Chris Scott 96e22dfa66 feat(servers): compact server switcher and mobile navigation for linked servers
Replace the Servers list with a single dropdown switcher in the sidebar, collapsed rail and mobile repo sheet, flagging activity on other servers. Show the More button on remote sessions, the tab bar on server and project pages, and the server name in a distinct color in the session header.
2026-10-19 10:36:43 -04:00

143 lines
4.4 KiB
TypeScript

import { useState } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { useDesktop } from '@/hooks/useDesktop'
import { useSidebarCollapsed } from '@/hooks/useSidebarCollapsed'
import { useSidebarWidth } from '@/hooks/useSidebarWidth'
import { useAuth } from '@/hooks/useAuth'
import { useUrlParams } from '@/hooks/useUrlParams'
import { useOpenNavItem } from '@/hooks/useOpenNavItem'
import { buildNavModel, type MoreDrawerItem, type NavPrimaryCta } from '@/components/navigation/moreDrawerItems'
import { RepoQuickSwitchSheet } from '@/components/navigation/RepoQuickSwitchSheet'
import { DesktopSessionTree } from '@/components/navigation/DesktopSessionTree'
import { LinkedServersNav } from '@/components/navigation/LinkedServersNav'
import {
Sidebar,
SidebarSection,
SidebarItem,
} from '@/components/ui/sidebar'
import { FolderGit2 } from 'lucide-react'
const FOOTER_ITEM_KEYS = new Set(['home', 'settings', 'logout'])
export function DesktopSidebar() {
const location = useLocation()
const navigate = useNavigate()
const { updateParams } = useUrlParams()
const openNavItem = useOpenNavItem()
const [collapsed, toggle] = useSidebarCollapsed()
const [sidebarWidth, setSidebarWidth] = useSidebarWidth()
const [repoSwitcherOpen, setRepoSwitcherOpen] = useState(false)
const { isAuthenticated, isLoading, logout } = useAuth()
const isDesktop = useDesktop()
if (isLoading || !isAuthenticated) {
return null
}
if (!isDesktop) {
return null
}
const { primary, items } = buildNavModel(location.pathname)
const handleItemClick = (item: MoreDrawerItem) => {
if (openNavItem(item)) return
if (item.key === 'logout') {
logout()
} else if (item.key === 'settings') {
updateParams((p) => {
p.set('settings', 'open')
p.set('settingsTab', 'account')
p.delete('mobileTab')
}, 'push')
} else if (item.key === 'repos') {
setRepoSwitcherOpen(true)
}
}
const footerItems = items.filter((item) => FOOTER_ITEM_KEYS.has(item.key))
const collapsedItems: MoreDrawerItem[] = [
footerItems[0],
{ key: 'repos', label: 'Repos', icon: FolderGit2 },
...footerItems.slice(1),
]
return (
<>
<Sidebar
collapsed={collapsed}
onToggle={toggle}
width={sidebarWidth}
onWidthChange={setSidebarWidth}
className='mt-2'
>
{primary.length > 0 && (
<SidebarSection collapsed={collapsed}>
{primary.map((item: NavPrimaryCta) => (
<SidebarItem
key={item.key}
icon={item.icon}
label={item.label}
collapsed={collapsed}
onClick={() => navigate(item.to)}
asPrimary
variant={item.variant}
/>
))}
</SidebarSection>
)}
{collapsed ? (
<>
<div className="flex flex-col gap-1 p-2 pt-0">
{collapsedItems.map((item: MoreDrawerItem) => (
<SidebarItem
key={item.key}
icon={item.icon}
label={item.label}
collapsed={collapsed}
onClick={() => handleItemClick(item)}
danger={item.danger}
/>
))}
</div>
<LinkedServersNav variant="rail" />
</>
) : (
<>
<div className="px-2 py-1">
<LinkedServersNav />
</div>
<section aria-label="Sessions" className="flex min-h-0 flex-1 flex-col border-t border-border">
<h2 className="px-3 py-1.5 text-xs font-medium uppercase tracking-wider text-muted-foreground">
Sessions
</h2>
<DesktopSessionTree />
</section>
<div className="flex gap-1 border-t border-border p-2">
{footerItems.map((item: MoreDrawerItem) => (
<SidebarItem
key={item.key}
icon={item.icon}
label={item.label}
collapsed
onClick={() => handleItemClick(item)}
danger={item.danger}
/>
))}
</div>
</>
)}
</Sidebar>
<RepoQuickSwitchSheet
isOpen={repoSwitcherOpen}
onClose={() => setRepoSwitcherOpen(false)}
/>
</>
)
}