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

ThreadHeader.tsx

104 lines3.9 KB

1import { useGT, useMessages } from "gt-react-native";
2import { useAtomValue } from "@effect/atom-react";
3import { AuthOrchestrationOperateScope, EnvironmentId } from "@t3tools/contracts";
4import * as Cause from "effect/Cause";
5import { AsyncResult } from "effect/reactivity";
6​
7import * as Dialog from "../../components/ui/Dialog";
8import { serverEnvironment } from "../../state/server";
9import { shellEnvironment } from "../../state/shell";
10import { readEnvironmentScope, useEnvironmentScope } from "../../state/session";
11import { useAtomCommand } from "../../state/use-atom-command";
12​
13import { AppBar } from "../../components/ui/AppBar";
14import type { AppBarAction, AppBarMenu } from "../../components/ui/AppBar.types";
15import {
16 useAdaptiveWorkspaceLayout,
17 useWorkspacePaneState,
18} from "../layout/AdaptiveWorkspaceLayout";
19import type { ThreadInspectorMode } from "./thread-inspector-navigation";
20import { useWorkspaceBackNavigation } from "../layout/workspace/useAndroidWorkspaceNavigation";
21import {
22 threadTerminalMenu,
23 useThreadGitMenuDefinition,
24 type ThreadGitControlsProps,
25} from "./ThreadGitControls";
26​
27export function ThreadHeader(props: {
28 readonly title: string;
29 readonly subtitle: string;
30 readonly gitControls: ThreadGitControlsProps;
31 readonly onReturnToThread?: () => void;
32 readonly draft?: boolean;
33 readonly hasThreadCwd: boolean;
34 readonly cwd: string | null;
35 readonly inspectorMode: ThreadInspectorMode | null;
36 readonly onOpenFilesInspector: () => void;
37}) {
38 const gt = useGT();
39 const m = useMessages();
40 const goBack = useWorkspaceBackNavigation();
41 const { toggleAuxiliaryPane, startNewTask } = useAdaptiveWorkspaceLayout();
42 const { panes } = useWorkspacePaneState();
43 const gitMenu = useThreadGitMenuDefinition(props.gitControls);
44 const terminalMenu = threadTerminalMenu(props.gitControls, m);
45 const environmentId = EnvironmentId.make(String(props.gitControls.environmentId));
46 const serverConfig = useAtomValue(serverEnvironment.configValueAtom(environmentId));
47 const canOperate = useEnvironmentScope(environmentId, AuthOrchestrationOperateScope);
48 const openInEditor = useAtomCommand(shellEnvironment.openInEditor, { reportFailure: false });
49 const filesVisible = props.inspectorMode === "files" && panes.auxiliaryPaneVisible;
50 const actions: AppBarAction[] = props.hasThreadCwd
51 ? [
52 {
53 accessibilityLabel: filesVisible ? gt`Close files` : gt`Open files`,
54 icon: "folder",
55 selected: filesVisible,
56 disabled: !props.gitControls.canOpenFiles,
57 separateBackground: false,
58 onPress: filesVisible ? toggleAuxiliaryPane : props.onOpenFilesInspector,
59 },
60 ]
61 : [];
62 if (props.cwd && serverConfig?.availableEditors.includes("devin")) {
63 actions.push({
64 accessibilityLabel: gt`Open in ${{ editor: "Devin" }}`,
65 icon: "desktopcomputer",
66 subtitle: serverConfig.environment.label,
67 overflowOnly: true,
68 disabled: !canOperate,
69 onPress: async () => {
70 if (!props.cwd || !readEnvironmentScope(environmentId, AuthOrchestrationOperateScope))
71 return;
72 const result = await openInEditor({
73 environmentId,
74 input: { cwd: props.cwd, editor: "devin" },
75 });
76 if (AsyncResult.isFailure(result)) {
77 Dialog.alert(gt`Open in ${{ editor: "Devin" }}`, String(Cause.squash(result.cause)));
78 }
79 },
80 });
81 }
82 const menus = [gitMenu, terminalMenu].filter((menu): menu is AppBarMenu => menu !== null);
83​
84 return (
85 <AppBar
86 title={props.title}
87 subtitle={props.subtitle}
88 onBackToList={goBack}
89 onCompose={props.draft ? undefined : startNewTask}
90 backInSplitView={
91 props.onReturnToThread
92 ? {
93 accessibilityLabel: gt`Return to chat`,
94 icon: "chevron.left",
95 onPress: props.onReturnToThread,
96 }
97 : undefined
98 }
99 actions={actions}
100 menus={menus}
101 hideBottomBorder
102 />
103 );