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

ThreadHeader.tsx

108 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-navigation";
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 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 compact={composerKeyboardActive}
104 />
105 {native.fallback}
106 </>
107 );