mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat(frontend): consolidate session picker navigation and remote project loading
This commit is contained in:
1 parent
81fb2d4033
commit
52aeb7780f
42 files changed
+1486
-769
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { sessionQueryOptions } from '@/hooks/useOpenCode'
|
||||
import { parseServerProjectRoute, parseServerSessionRoute } from '@/lib/navigation'
|
||||
|
||||
/**
|
||||
* Resolves the linked server directory currently in view: the project route's directory when one
|
||||
* matches the server, otherwise the directory of the session route it belongs to.
|
||||
*
|
||||
* @param serverId Linked server whose active directory is resolved.
|
||||
* @param options.enabled Whether the session lookup may run; omit for routes that always resolve it.
|
||||
* @returns The active directory, or null when neither route identifies one.
|
||||
*/
|
||||
export function useActiveRemoteDirectory(
|
||||
serverId: string,
|
||||
{ enabled = true }: { enabled?: boolean } = {},
|
||||
): string | null {
|
||||
const { pathname, search } = useLocation()
|
||||
const projectRoute = parseServerProjectRoute(pathname, search)
|
||||
const sessionRoute = parseServerSessionRoute(pathname)
|
||||
const sessionID = sessionRoute?.serverId === serverId ? sessionRoute.sessionId : undefined
|
||||
const { data: session } = useQuery({
|
||||
...sessionQueryOptions(sessionID, undefined, serverId),
|
||||
enabled: Boolean(sessionID) && enabled,
|
||||
})
|
||||
|
||||
if (projectRoute?.serverId === serverId) return projectRoute.directory
|
||||
return session?.location.directory ?? null
|
||||
}
|
||||
Reference in new issue
Block a user