Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

use-thread-pr.ts

41 lines1.3 KB

1import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2​
3import { useEnvironmentQuery } from "./query";
4import { presentThreadPr, type ThreadPrPresentation } from "./thread-pr-presentation";
5import { vcsEnvironment } from "./vcs";
6​
7export {
8 presentThreadPr,
9 type ThreadPr,
10 type ThreadPrPresentation,
11} from "./thread-pr-presentation";
12​
13/**
14 * Live PR status for a thread's branch. Subscriptions are deduplicated per
15 * (environmentId, cwd) by the atom family, so many rows on the same worktree
16 * or project root share one stream — and virtualization means only visible
17 * rows subscribe at all.
18 */
19export function useThreadPr(
20 thread: EnvironmentThreadShell,
21 projectCwd: string | null,
22): ThreadPrPresentation | null {
23 const cwd = thread.worktreePath ?? projectCwd;
24 const gitStatus = useEnvironmentQuery(
25 thread.branch !== null && cwd !== null
26 ? vcsEnvironment.status({
27 environmentId: thread.environmentId,
28 input: { cwd },
29 })
30 : null,
31 );
32​
33 const status = gitStatus.data;
34 if (status === null || thread.branch === null || status.refName !== thread.branch) {
35 return null;
36 }
37 if (!status.pr) {
38 return null;
39 }
40 return presentThreadPr(status.pr, status.sourceControlProvider);