The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 59 lines 2.39 KB
Raw
1 import { useEnvironmentQuery } from "../../state/query";
2 import { useSelectedThreadGitActions } from "../../state/use-selected-thread-git-actions";
3 import { useSelectedThreadGitState } from "../../state/use-selected-thread-git-state";
4 import { useThreadSelection } from "../../state/use-thread-selection";
5 import { vcsEnvironment } from "../../state/vcs";
6 import { useThreadGitMenuDefinition } from "../threads/ThreadGitControls";
7 import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
8 import type { ReviewSectionItem } from "./reviewModel";
9 import type { AppBarMenuItem, AppBarMenu } from "../../components/ui/AppBar.types";
10 import type { AppSymbolName } from "../../components/ui/AppSymbol";
11
12 interface ReviewHeaderPresentation {
13 readonly title: string;
14 readonly subtitle: string;
15 readonly gitMenu: AppBarMenu | null;
16 readonly menuIcon: AppSymbolName;
17 readonly refreshAction?: AppBarMenuItem;
18 }
19
20 export function useReviewHeaderPresentation(props: {
21 readonly environmentId: EnvironmentId;
22 readonly threadId: ThreadId;
23 readonly title: string;
24 readonly subtitle: string;
25 readonly androidSubtitle: string;
26 readonly selectedThreadCwd: string | null;
27 readonly selectedSection: ReviewSectionItem | null;
28 readonly onRefresh: () => Promise<void>;
29 }): ReviewHeaderPresentation {
30 const { selectedThread } = useThreadSelection();
31 const gitState = useSelectedThreadGitState();
32 const gitActions = useSelectedThreadGitActions();
33 const gitStatusQuery = useEnvironmentQuery(
34 selectedThread !== null && props.selectedThreadCwd !== null
35 ? vcsEnvironment.status({
36 environmentId: selectedThread.environmentId,
37 input: { cwd: props.selectedThreadCwd },
38 })
39 : null,
40 );
41 // Selection-based git hooks apply only to reviews of the selected thread.
42 const gitMenuAvailable =
43 selectedThread !== null && String(selectedThread.id) === String(props.threadId);
44 const gitMenu = useThreadGitMenuDefinition({
45 environmentId: props.environmentId,
46 threadId: props.threadId,
47 currentBranch: selectedThread?.branch ?? null,
48 gitStatus: gitStatusQuery.data,
49 gitOperationLabel: gitState.gitOperationLabel,
50 onPull: gitActions.onPullSelectedThreadBranch,
51 onRunAction: gitActions.onRunSelectedThreadGitAction,
52 });
53 return {
54 title: props.title,
55 subtitle: props.subtitle,
56 menuIcon: "ellipsis",
57 gitMenu: gitMenuAvailable ? gitMenu : null,
58 };
59 }