Files
opencode-manager/frontend/src/components/navigation/DesktopSidebar.tsx
T
Chris Scott 16f9f9c2ee feat(source-control): edge-anchored sidebar toggle, branches header cleanup, orange current-branch accents (#349)
* feat(source-control): edge-anchored sidebar toggle, branches header cleanup, orange current-branch accents

* feat(settings): sidebar navigation with per-tab two-column layouts and mobile menu landing

* fix(ui): re-measure prompt overlay after edit remount and anchor mobile stop button above input
2026-09-09 10:57:35 -04:00

117 lines
3.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 { emitSidebarAction } from '@/hooks/useSidebarAction'
import { useAuth } from '@/hooks/useAuth'
import { useUrlParams } from '@/hooks/useUrlParams'
import { buildNavModel, type MoreDrawerItem, type NavPrimaryCta } from '@/components/navigation/moreDrawerItems'
import { getPathWithReturnTo } from '@/lib/navigation'
import { RepoQuickSwitchSheet } from '@/components/navigation/RepoQuickSwitchSheet'
import {
Sidebar,
SidebarSection,
SidebarItem,
} from '@/components/ui/sidebar'
import { FolderGit2 } from 'lucide-react'
export function DesktopSidebar() {
const location = useLocation()
const navigate = useNavigate()
const { updateParams } = useUrlParams()
const [collapsed, toggle] = useSidebarCollapsed()
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 handlePrimaryClick = (item: NavPrimaryCta) => {
if (item.to) {
navigate(item.to)
} else if (item.onSelect) {
emitSidebarAction(item.onSelect)
}
}
const handleItemClick = (item: MoreDrawerItem) => {
if (item.to) {
const to = item.key === 'schedules'
? getPathWithReturnTo(item.to, `${location.pathname}${location.search}`)
: item.to
navigate(to)
} else if (item.dialog) {
updateParams((p) => {
p.set('dialog', item.dialog!)
p.delete('mobileTab')
}, 'push')
} else 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 [homeItem, ...routeItems] = items
const navItems: MoreDrawerItem[] = [
homeItem,
{ key: 'repos', label: 'Repos', icon: FolderGit2 },
...routeItems,
]
return (
<>
<Sidebar collapsed={collapsed} onToggle={toggle} 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={() => handlePrimaryClick(item)}
asPrimary
variant={item.variant}
/>
))}
</SidebarSection>
)}
<div className="flex flex-col gap-1 p-2 pt-0">
{navItems.map((item: MoreDrawerItem) => (
<SidebarItem
key={item.key}
icon={item.icon}
label={item.label}
collapsed={collapsed}
onClick={() => handleItemClick(item)}
danger={item.danger}
/>
))}
</div>
</Sidebar>
<RepoQuickSwitchSheet
isOpen={repoSwitcherOpen}
onClose={() => setRepoSwitcherOpen(false)}
/>
</>
)
}