mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Sheet, desktop rail and session-page dialog resolve the same canonical remote project, reuse the page's session cache and hold the all-directories search while it resolves. Deleting the open session keeps ?repoTab=. Context usage keeps its identity between streaming flushes so ModelQuickSelect skips re-renders, the location prefetch waits for repo data, and dialog and bottom sheet share one return-focus hook. Picker route parsing, remote project query options and the local new-session button are shared.
29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
import { useEffect } from 'react'
|
|
import { useLocation } from 'react-router-dom'
|
|
import { useQueryClient } from '@tanstack/react-query'
|
|
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
|
import { openCodeLocationQueryOptions } from '@/lib/openCodeLocation'
|
|
import { parseRepoRoute } from '@/lib/navigation'
|
|
import { useNavigableRepos } from '@/hooks/useSidebarRepoGroups'
|
|
|
|
/**
|
|
* Warms the picker's project location on a local repo route so the first session picker open does
|
|
* not serialise the location lookup ahead of the session list. The repo path comes from the repos
|
|
* query the repo worktrees provider already observes, so a route restored before that query settles
|
|
* still prefetches once the repo data arrives. The prefetch never creates a query observer.
|
|
*/
|
|
export function useSessionPickerLocationPrefetch(): void {
|
|
const { pathname } = useLocation()
|
|
const queryClient = useQueryClient()
|
|
const { repos } = useNavigableRepos()
|
|
const repoId = parseRepoRoute(pathname).repoId
|
|
const repoPath = repos.find((repo) => repo.id === repoId)?.fullPath
|
|
|
|
useEffect(() => {
|
|
if (repoPath === undefined) return
|
|
void queryClient.prefetchQuery(
|
|
openCodeLocationQueryOptions(repoPath, LOCAL_OPENCODE_SERVER_ID),
|
|
)
|
|
}, [queryClient, repoPath])
|
|
}
|