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

ThreadHeader.tsx

109 lines3.7 KB

1import { useMemo } from "react";
2import { AppBar } from "../../components/ui/AppBar";
3import { ScreenHeaderButton } from "../../components/ui/ScreenHeaderButton";
4import type { AppBarAction } from "../../components/ui/AppBar.types";
5import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
6import type { ThreadInspectorMode } from "./thread-inspector-content-stack";
7import { useThreadHeaderOptions } from "./useThreadHeaderOptions";
8import { useWorkspaceBackNavigation } from "../workspace/useAndroidWorkspaceNavigation";
9import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
10​
11export function ThreadHeader(
12 props: Parameters<typeof useThreadHeaderOptions>[0] & {
13 readonly hasThreadCwd: boolean;
14 readonly hasWorkspaceRoot: boolean;
15 readonly fileInspectorSupported: boolean;
16 readonly inspectorMode: ThreadInspectorMode | null;
17 readonly onToggleInspector: () => void;
18 readonly onOpenGitInspector: () => void;
19 readonly onOpenFilesInspector: () => void;
20 },
21) {
22 const goBack = useWorkspaceBackNavigation("threads");
23 const { layout, panes, toggleAuxiliaryPane, composerKeyboardActive } =
24 useAdaptiveWorkspaceLayout();
25 const { onOpenTerminal, onMergeBack } = props.gitControls;
26 const native = useThreadHeaderOptions(props);
27 const androidHeaderActions = useMemo<ReadonlyArray<AppBarAction>>(() => {
28 const actions: AppBarAction[] = [];
29 if (props.onReturnToThread) {
30 actions.push({
31 accessibilityLabel: "Return to chat",
32 icon: "chevron.left",
33 onPress: props.onReturnToThread,
34 });
35 }
36 if (props.hasThreadCwd) {
37 const filesVisible = props.inspectorMode === "files" && panes.auxiliaryPaneVisible;
38 actions.push({
39 accessibilityLabel: filesVisible ? "Close files" : "Open files",
40 selected: filesVisible,
41 icon: "folder",
42 onPress: filesVisible ? toggleAuxiliaryPane : props.onOpenFilesInspector,
43 });
44 }
45 if (props.hasWorkspaceRoot && props.gitControls.canOpenTerminal) {
46 actions.push({
47 accessibilityLabel: "Open terminal",
48 icon: "terminal",
49 onPress: () => onOpenTerminal(null),
50 });
51 }
52 actions.push({
53 accessibilityLabel: "Open git controls",
54 icon: "point.topleft.down.curvedto.point.bottomright.up",
55 onPress: props.onOpenGitInspector,
56 });
57 if (onMergeBack) {
58 actions.push({
59 accessibilityLabel: "Merge back to source",
60 icon: PullRequestGlyph.merged,
61 onPress: onMergeBack,
62 });
63 }
64 return actions;
65 }, [
66 props.inspectorMode,
67 panes.auxiliaryPaneVisible,
68 props.onOpenFilesInspector,
69 onOpenTerminal,
70 onMergeBack,
71 props.onOpenGitInspector,
72 toggleAuxiliaryPane,
73 props.onReturnToThread,
74 props.hasThreadCwd,
75 props.hasWorkspaceRoot,
76 props.gitControls.canOpenTerminal,
77 ]);
78​
79 return (
80 <>
81 <AppBar
82 title={props.title}
83 subtitle={props.subtitle}
84 sidebar={native.sidebar}
85 options={native.options}
86 optionsVersion={native.optionsVersion}
87 trailing={
88 props.fileInspectorSupported && props.hasThreadCwd ? (
89 <ScreenHeaderButton
90 accessibilityLabel={
91 props.inspectorMode !== null && panes.auxiliaryPaneVisible
92 ? "Hide inspector"
93 : "Show inspector"
94 }
95 icon="sidebar.right"
96 selected={props.inspectorMode !== null && panes.auxiliaryPaneVisible}
97 onPress={props.onToggleInspector}
98 />
99 ) : null
100 }
101 onBack={layout.usesSplitView ? undefined : goBack}
102 actions={androidHeaderActions}
103 hideBottomBorder
104 compact={composerKeyboardActive}
105 />
106 {native.fallback}
107 </>
108 );