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

WorkspaceRootScreen.android.tsx

101 lines3.9 KB

1import { WorkspaceNoTabs } from "./WorkspaceNoTabs";
2import { useEnabledNavigationTabs } from "./navigation-tabs";
3import { NAVIGATION_TAB_ORDER } from "./navigation-tab-order";
4import { WorkspaceExtraTab } from "./WorkspaceExtraTab";
5import { useMemo } from "react";
6import { View } from "react-native";
7import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
8import { NativeStackScreenOptions } from "../../native/StackHeader";
9import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
10import { EmptyState } from "../../components/ui/EmptyState";
11import { ScreenContent } from "../../components/ui/ScreenContent";
12import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
13import { HomeRouteScreen } from "../home/HomeRouteScreen";
14import { PullRequestFilterMenuProvider } from "../pull-requests/PullRequestFilterMenuContext";
15import { PullRequestsScreen } from "../pull-requests/PullRequestsScreen";
16import { PullRequestToolbar } from "../pull-requests/PullRequestToolbar.android";
17import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
18import { AndroidWorkspaceNavigation } from "./AndroidWorkspaceNavigation";
19import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
20import { WorkspaceTabPanes } from "./WorkspaceTabPanes";
21import type { WorkspaceTab } from "./workspace-tabs-state";
22​
23const TABS: readonly WorkspaceTab[] = NAVIGATION_TAB_ORDER;
24​
25export function WorkspaceRootScreen() {
26 const { layout, startNewTask } = useAdaptiveWorkspaceLayout();
27 const workspace = useWorkspaceTabs()!;
28 const enabled = useEnabledNavigationTabs();
29 const insets = useSafeAreaInsets();
30 const { fabClearance } = useAndroidControlSizing();
31 const context = useMemo(
32 () => ({
33 ...workspace,
34 bottomClearance: workspace.state.selectedTab === "threads" ? fabClearance + 16 : 16,
35 }),
36 [workspace, fabClearance],
37 );
38 const tab = workspace.state.selectedTab;
39​
40 if (layout.usesSplitView) {
41 if (enabled.length === 0) return <View className="flex-1 bg-screen" />;
42 return (
43 <WorkspaceTabPanes
44 tabs={TABS}
45 selected={tab}
46 renderTab={(tab) =>
47 tab === "threads" ? (
48 <HomeRouteScreen />
49 ) : tab !== "pullRequests" ? (
50 <WorkspaceExtraTab tab={tab} />
51 ) : (
52 <>
53 <NativeStackScreenOptions options={{ headerShown: false }} />
54 <AndroidScreenHeader title="Pull requests" />
55 <View className="flex-1 items-center justify-center px-10">
56 <EmptyState
57 title="Select a pull request"
58 detail="Choose a pull request from the sidebar to review it."
59 variant="plain"
60 />
61 </View>
62 </>
63 )
64 }
65 />
66 );
67 }
68​
69 return (
70 <WorkspaceTabsContext value={context}>
71 <View className="flex-1 bg-header">
72 <NativeStackScreenOptions options={{ headerShown: false }} />
73 <SafeAreaInsetsContext value={{ ...insets, bottom: 0 }}>
74 {enabled.length === 0 ? (
75 <WorkspaceNoTabs />
76 ) : (
77 <WorkspaceTabPanes
78 tabs={TABS}
79 selected={tab}
80 renderTab={(tab) =>
81 tab === "threads" ? (
82 <HomeRouteScreen />
83 ) : tab !== "pullRequests" ? (
84 <WorkspaceExtraTab tab={tab} />
85 ) : (
86 <PullRequestFilterMenuProvider>
87 <PullRequestToolbar />
88 <ScreenContent>
89 <PullRequestsScreen />
90 </ScreenContent>
91 </PullRequestFilterMenuProvider>
92 )
93 }
94 />
95 )}
96 </SafeAreaInsetsContext>
97 <AndroidWorkspaceNavigation onNewThread={startNewTask} />
98 </View>
99 </WorkspaceTabsContext>
100 );