@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
tsx 164 lines 6.75 KB
Raw
1 import { useGT } from "gt-react-native";
2 import { useAndroidFloatingTabs } from "../../settings/appearance/AppearancePreferencesProvider";
3 import { WorkspaceNoTabs } from "./WorkspaceNoTabs";
4 import { useEnabledNavigationTabs } from "./navigation-tabs";
5 import { NAVIGATION_TAB_ORDER } from "./navigation-tab-order";
6 import { WorkspaceExtraTab } from "./WorkspaceExtraTab";
7 import type { ReactNode } from "react";
8 import { View } from "react-native";
9 import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
10 import { NativeStackScreenOptions } from "../../../native/StackHeader";
11 import { AppBar } from "../../../components/ui/AppBar";
12 import { WorkspaceEmptyDetail } from "../WorkspaceEmptyDetail";
13 import { ScreenContent } from "../../../components/ui/ScreenContent";
14 import { useAndroidControlSizing } from "../../../components/ui/useAndroidControlSizing";
15 import { HomeRouteScreen } from "../../home/HomeRouteScreen";
16 import { PullRequestsScreen } from "../../pull-requests/PullRequestsScreen";
17 import { ListSearchToolbar } from "./ListSearchToolbar.android";
18 import { IssuesScreen } from "../../issues/IssuesScreen";
19 import { useAdaptiveWorkspaceLayout } from "../AdaptiveWorkspaceLayout";
20 import { WorkspaceSettledContentWidthContext } from "../workspace-content-width";
21 import { AndroidWorkspaceNavigation, FloatingWorkspaceTabs } from "./AndroidWorkspaceNavigation";
22 import { FLOATING_TABS } from "./floating-workspace-tabs";
23 import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
24 import { WorkspaceTabPanes } from "./WorkspaceTabPanes";
25 import { WorkspaceAppBarScope } from "../../../components/ui/WorkspaceAppBar.android";
26 import { usePaneRole } from "../../../components/ui/Pane";
27 import { AndroidWorkspaceSidebar } from "./AndroidWorkspaceSidebar.android";
28 import type { WorkspaceTab } from "./workspace-tabs-state";
29 import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
30 import { useHardwareBack } from "../../../lib/backHandler";
31
32 const TABS: readonly WorkspaceTab[] = NAVIGATION_TAB_ORDER;
33
34 export function WorkspaceRootScreen() {
35 return usePaneRole() === "sidebar" ? <AndroidWorkspaceSidebar /> : <WorkspaceRoot />;
36 }
37
38 function WorkspaceRoot() {
39 const gt = useGT();
40 const floatingTabsEnabled = useAndroidFloatingTabs();
41 const { layout, startNewTask, workspacePageWidth } = useAdaptiveWorkspaceLayout();
42 const workspace = useWorkspaceTabs()!;
43 const enabled = useEnabledNavigationTabs();
44 const insets = useSafeAreaInsets();
45 const { fabClearance, fabSize } = useAndroidControlSizing();
46 const context = {
47 ...workspace,
48 bottomClearance: layout.usesSplitView
49 ? workspace.bottomClearance
50 : floatingTabsEnabled
51 ? insets.bottom + FLOATING_TABS.bottom + FLOATING_TABS.edge + fabSize
52 : workspace.state.selectedTab === "threads"
53 ? fabClearance + 16
54 : 16,
55 };
56 const tab = workspace.state.selectedTab;
57 const selectTab = useSelectWorkspaceTab();
58 // Tabs are panes of Home, not routes, so Back has nothing to pop and would leave the app.
59 // An open search keeps Back for itself.
60 useHardwareBack(
61 tab !== "threads" &&
62 enabled.includes("threads") &&
63 workspace.state.tabs[tab].searchMode === "resting",
64 () => {
65 selectTab("threads");
66 return true;
67 },
68 );
69
70 return (
71 <WorkspaceTabsContext value={context}>
72 <View className={layout.usesSplitView ? "flex-1 bg-screen" : "flex-1 bg-header"}>
73 {!layout.usesSplitView ? (
74 <NativeStackScreenOptions options={{ headerShown: false }} />
75 ) : null}
76 <SafeAreaInsetsContext
77 value={
78 layout.usesSplitView
79 ? insets
80 : floatingTabsEnabled
81 ? tab === "usage"
82 ? { ...insets, bottom: context.bottomClearance }
83 : insets
84 : { ...insets, bottom: 0 }
85 }
86 >
87 {enabled.length === 0 ? (
88 layout.usesSplitView ? (
89 <View className="flex-1 bg-screen" />
90 ) : (
91 <WorkspaceNoTabs />
92 )
93 ) : (
94 <WorkspaceAppBarScope enabled={!layout.usesSplitView}>
95 <WorkspaceTabPanes
96 tabs={TABS}
97 selected={tab}
98 renderTab={(tab) =>
99 tab === "threads" ? (
100 <HomeRouteScreen />
101 ) : tab === "usage" ? (
102 <WorkspacePageFrame width={workspacePageWidth ?? null}>
103 <WorkspaceExtraTab tab={tab} />
104 </WorkspacePageFrame>
105 ) : layout.usesSplitView ? (
106 <>
107 <NativeStackScreenOptions options={{ headerShown: false }} />
108 <AppBar
109 embedded
110 title={
111 tab === "issues"
112 ? gt("Issues", { $context: "screen title, list of issues" })
113 : gt("Pull requests")
114 }
115 />
116 <WorkspaceEmptyDetail tab={tab} />
117 </>
118 ) : tab === "issues" ? (
119 <IssuesScreen
120 renderFrame={(filters, list) => (
121 <>
122 <ListSearchToolbar tab="issues" filters={filters} />
123 <ScreenContent>{list}</ScreenContent>
124 </>
125 )}
126 />
127 ) : (
128 <PullRequestsScreen
129 renderFrame={(filters, list) => (
130 <>
131 <ListSearchToolbar tab="pullRequests" filters={filters} />
132 <ScreenContent>{list}</ScreenContent>
133 </>
134 )}
135 />
136 )
137 }
138 />
139 </WorkspaceAppBarScope>
140 )}
141 </SafeAreaInsetsContext>
142 {layout.usesSplitView ? null : floatingTabsEnabled ? (
143 <FloatingWorkspaceTabs fillWidth onNewThread={startNewTask} />
144 ) : (
145 <AndroidWorkspaceNavigation onNewThread={startNewTask} />
146 )}
147 </View>
148 </WorkspaceTabsContext>
149 );
150 }
151
152 // Hidden, the page sits in the narrower pane beside the list; laying it out at the width it opens
153 // at keeps measured bars and breakpoints from catching up a frame after it appears.
154 function WorkspacePageFrame(props: {
155 readonly width: number | null;
156 readonly children: ReactNode;
157 }) {
158 if (props.width === null) return props.children;
159 return (
160 <WorkspaceSettledContentWidthContext value={props.width}>
161 <View style={{ flex: 1, width: props.width }}>{props.children}</View>
162 </WorkspaceSettledContentWidthContext>
163 );
164 }