Files
opencode-manager/frontend/src/hooks/useRepoWorktrees.ts
T
Chris Scott bfbbbf08ef fix(activity): surface worktree sessions in active work, the sidebar and repo badges
- Resolve sessions in repo worktrees to the owning repo in the activity list; show the worktree branch and open the Workspaces tab
- Look up worktrees only for unmatched sessions in the window or under an active root, and hold the loading state until it settles
- Show schedule-worktree sessions only while running or needing input
- Light repo badges for worktree sessions through one app-wide worktree lookup
- List worktree sessions under the expanded repo in the sidebar
- Subscribe the event stream to active session directories so worktree permissions and forms arrive
- Keep the worktree tab when navigating from the desktop Activity panel
- Remove the braille spinner's always-dim bottom row
2026-10-16 20:36:56 +00:00

29 lines
1.1 KiB
TypeScript

import { useQueries } from '@tanstack/react-query'
import { getRepoSiblings } from '@/api/repos'
import { repoSiblingsQueryKey } from '@/hooks/useRepoSiblings'
import { buildWorktreeActivity, type ActiveWorktree } from '@/lib/activeWork'
import type { Repo } from '@/api/types'
/**
* Discovers each repo's worktrees from its siblings while enabled, keyed by directory so a session
* running in a worktree resolves to the repo that owns it. Each query is skipped for repos without
* a positive id. `isLoading` is true while any enabled siblings query is still loading.
*/
export function useRepoWorktrees(
repos: Repo[],
enabled: boolean,
): { worktrees: ActiveWorktree[]; isLoading: boolean } {
return useQueries({
queries: repos.map((repo) => ({
queryKey: repoSiblingsQueryKey(repo.id),
queryFn: () => getRepoSiblings(repo.id),
enabled: enabled && repo.id > 0,
staleTime: 30_000,
})),
combine: (results) => ({
worktrees: buildWorktreeActivity(repos, results),
isLoading: results.some((result) => result.isLoading),
}),
})
}