feat(servers): switch the sidebar listing between local and linked servers

The Servers section becomes a Local/server switcher shared by the desktop sidebar, collapsed rail and mobile repo sheet. Selecting a linked server lists its projects and sessions with the same navigation as local repos, and a remote project page mirrors the local repo page.
This commit is contained in:
Chris Scott committed 2026-10-19 10:16:32 -04:00
1 parent cb9b7645e6
commit 36b8c1b200
29 files changed
+2080 -201

No files matched your search

@@ -0,0 +1,44 @@
import { useEffect } from 'react'
import { useLocation, useMatch } from 'react-router-dom'
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
import { useOpenCodeServers } from '@/hooks/useOpenCodeServers'
import { isAssistantPath, parseRepoRoute } from '@/lib/navigation'
import { useSidebarServerStore } from '@/stores/sidebarServerStore'
function isLocalRoute(pathname: string): boolean {
return parseRepoRoute(pathname).repoId !== null || isAssistantPath(pathname)
}
/**
* The linked server selected in the sidebar, defaulting to the local server. The route selects a
* server when the location changes, selecting a row never navigates, and a selected server that is
* missing or disabled falls back to local.
*/
export function useSidebarServerSelection(): [string, (serverId: string) => void] {
const { pathname } = useLocation()
const routeServerId = useMatch('/servers/:serverId/*')?.params.serverId
const { servers, isLoading } = useOpenCodeServers()
const serverId = useSidebarServerStore((state) => state.serverId)
const selectServer = useSidebarServerStore((state) => state.selectServer)
useEffect(() => {
const current = useSidebarServerStore.getState().serverId
if (routeServerId) {
if (current !== routeServerId) selectServer(routeServerId)
return
}
if (isLocalRoute(pathname) && current !== LOCAL_OPENCODE_SERVER_ID) {
selectServer(LOCAL_OPENCODE_SERVER_ID)
}
}, [pathname, routeServerId, selectServer])
useEffect(() => {
if (isLoading || serverId === LOCAL_OPENCODE_SERVER_ID) return
const server = servers.find((candidate) => candidate.id === serverId)
if (!server || !server.enabled) {
selectServer(LOCAL_OPENCODE_SERVER_ID)
}
}, [isLoading, servers, serverId, selectServer])
return [serverId, selectServer]
}