Open History to see the last commit
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 } = useAdaptiveWorkspaceLayout();
24 const { onOpenTerminal, onMergeBack } = props.gitControls;
25 const native = useThreadHeaderOptions(props);
26 const androidHeaderActions = useMemo<ReadonlyArray<AppBarAction>>(() => {
27 const actions: AppBarAction[] = [];
28 if (props.onReturnToThread) {
29 actions.push({
30 accessibilityLabel: "Return to chat",
31 icon: "chevron.left",
32 onPress: props.onReturnToThread,
33 });
34 }
35 if (props.hasThreadCwd) {
36 const filesVisible = props.inspectorMode === "files" && panes.auxiliaryPaneVisible;
37 actions.push({
38 accessibilityLabel: filesVisible ? "Close files" : "Open files",
39 selected: filesVisible,
40 icon: "folder",
41 onPress: filesVisible ? toggleAuxiliaryPane : props.onOpenFilesInspector,
42 });
43 }
44 if (props.hasWorkspaceRoot && props.gitControls.canOpenTerminal) {
45 actions.push({
46 accessibilityLabel: "Open terminal",
47 icon: "terminal",
48 onPress: () => onOpenTerminal(null),
49 });
50 }
51 actions.push({
52 accessibilityLabel: "Open git controls",
53 icon: "point.topleft.down.curvedto.point.bottomright.up",
54 onPress: props.onOpenGitInspector,
55 });
56 if (onMergeBack) {
57 actions.push({
58 accessibilityLabel: "Merge back to source",
59 icon: PullRequestGlyph.merged,
60 onPress: onMergeBack,
61 });
62 }
63 return actions;
64 }, [
65 props.inspectorMode,
66 panes.auxiliaryPaneVisible,
67 props.onOpenFilesInspector,
68 onOpenTerminal,
69 onMergeBack,
70 props.onOpenGitInspector,
71 toggleAuxiliaryPane,
72 props.onReturnToThread,
73 props.hasThreadCwd,
74 props.hasWorkspaceRoot,
75 props.gitControls.canOpenTerminal,
76 ]);
77
78 return (
79 <>
80 <AppBar
81 title={props.title}
82 subtitle={props.subtitle}
83 sidebar={native.sidebar}
84 options={native.options}
85 optionsVersion={native.optionsVersion}
86 trailing={
87 props.fileInspectorSupported && props.hasThreadCwd ? (
88 <ScreenHeaderButton
89 accessibilityLabel={
90 props.inspectorMode !== null && panes.auxiliaryPaneVisible
91 ? "Hide inspector"
92 : "Show inspector"
93 }
94 icon="sidebar.right"
95 selected={props.inspectorMode !== null && panes.auxiliaryPaneVisible}
96 onPress={props.onToggleInspector}
97 />
98 ) : null
99 }
100 onBack={layout.usesSplitView ? undefined : goBack}
101 actions={androidHeaderActions}
102 hideBottomBorder
103 />
104 {native.fallback}
105 </>
106 );
107}