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

SettingsNavigationRouteScreen.tsx

138 lines5.8 KB

1import { useGT, useMessages } from "gt-react-native";
2import { useAtomValue } from "@effect/atom-react";
3import { AsyncResult } from "effect/reactivity";
4import { useAdaptiveWorkspaceLayout } from "../layout/adaptive-workspace-context";
5import { Platform, View } from "react-native";
6import { useSafeAreaInsets } from "react-native-safe-area-context";
7import {
8 moveNavigationTab,
9 navigationCustomizationAvailable,
10 toggleNavigationTabVisibility,
11} from "../layout/workspace/navigation-tab-order";
12import { AppText as Text } from "../../components/ui/AppText";
13import { IconButton } from "../../components/ui/IconButton";
14import { Button } from "../../components/ui/Button";
15import { ScreenScrollView } from "../../components/ui/ScreenScrollView";
16import { SymbolView } from "../../components/ui/AppSymbol";
17import { mobilePreferencesAtom, saveMobilePreferences } from "../../state/preferences";
18import { useAtomCommand } from "../../state/use-atom-command";
19import {
20 NAVIGATION_TAB_ICONS,
21 WORKSPACE_TAB_LABELS,
22 useNavigationTabOrder,
23 useHiddenNavigationTabs,
24 useEnabledNavigationTabs,
25} from "../layout/workspace/navigation-tabs";
26import { SettingsScreen } from "./components/SettingsScreen";
27import { SettingsSection } from "./components/SettingsSection";
28import { resolveWorkspaceTabOrder } from "../layout/workspace/workspace-tabs-state";
29​
30export function SettingsNavigationRouteScreen() {
31 const gt = useGT();
32 const m = useMessages();
33 const insets = useSafeAreaInsets();
34 const order = useNavigationTabOrder();
35 const { layout } = useAdaptiveWorkspaceLayout();
36 const capacity = Platform.OS === "android" && layout.usesSplitView ? 5 : 4;
37 const hidden = useHiddenNavigationTabs();
38 const enabled = useEnabledNavigationTabs();
39 const preferences = useAtomValue(mobilePreferencesAtom);
40 const customizable = navigationCustomizationAvailable();
41 const ready = customizable && AsyncResult.isSuccess(preferences) && !preferences.waiting;
42 const save = useAtomCommand(saveMobilePreferences);
43 return (
44 <SettingsScreen title={gt`Navigation tabs`}>
45 <ScreenScrollView
46 contentInsetAdjustmentBehavior="automatic"
47 contentContainerClassName="gap-4 px-5 pt-4"
48 contentContainerStyle={{ paddingBottom: insets.bottom + 24 }}
49 >
50 <Text className="px-2 text-sm text-foreground-muted">
51 {customizable
52 ? gt`Phones show the first four enabled sections; Android tablet rails show all enabled sections. Remaining sections appear at the top of Settings. Hidden sections appear only here. Settings always stays last. Saved on this device.`
53 : gt`Tab customization becomes available when there are six sections, including Settings.`}
54 </Text>
55 <SettingsSection title={gt`Tab order`}>
56 {order.map((tab, index) => (
57 <View key={tab} className="flex-row items-center gap-3 px-4 py-3">
58 <SymbolView
59 name={NAVIGATION_TAB_ICONS[tab]}
60 size={22}
61 tintColorClassName="accent-icon"
62 />
63 <View className="flex-1">
64 <Text>{m(WORKSPACE_TAB_LABELS[tab])}</Text>
65 <Text className="text-xs text-foreground-muted">
66 {hidden.includes(tab)
67 ? gt({ context: "navigation tab visibility status" })`Hidden`
68 : enabled.indexOf(tab) < capacity
69 ? gt`Tab ${{ position: enabled.indexOf(tab) + 1 }}`
70 : gt`In Settings`}
71 </Text>
72 </View>
73 <IconButton
74 icon={hidden.includes(tab) ? "eye.slash" : "eye"}
75 accessibilityLabel={
76 hidden.includes(tab)
77 ? gt`Show ${{ tab: m(WORKSPACE_TAB_LABELS[tab]) }}`
78 : gt`Hide ${{ tab: m(WORKSPACE_TAB_LABELS[tab]) }}`
79 }
80 disabled={!ready}
81 onPress={() => {
82 void save({
83 transform: (current) => ({
84 hiddenNavigationTabs: toggleNavigationTabVisibility(
85 current.hiddenNavigationTabs,
86 tab,
87 ),
88 }),
89 });
90 }}
91 />
92 <IconButton
93 icon="arrow.up"
94 accessibilityLabel={gt`Move ${{ tab: m(WORKSPACE_TAB_LABELS[tab]) }} up`}
95 disabled={!ready || index === 0}
96 onPress={() => {
97 void save({
98 transform: (current) => ({
99 navigationTabOrder: moveNavigationTab(
100 resolveWorkspaceTabOrder(current.navigationTabOrder),
101 tab,
102 index - 1,
103 ),
104 }),
105 });
106 }}
107 />
108 <IconButton
109 icon="arrow.down"
110 accessibilityLabel={gt`Move ${{ tab: m(WORKSPACE_TAB_LABELS[tab]) }} down`}
111 disabled={!ready || index === order.length - 1}
112 onPress={() => {
113 void save({
114 transform: (current) => ({
115 navigationTabOrder: moveNavigationTab(
116 resolveWorkspaceTabOrder(current.navigationTabOrder),
117 tab,
118 index + 1,
119 ),
120 }),
121 });
122 }}
123 />
124 </View>
125 ))}
126 </SettingsSection>
127 <Button
128 label={gt`Reset tabs`}
129 tone="text"
130 disabled={!ready}
131 onPress={() => {
132 void save({ navigationTabOrder: [], hiddenNavigationTabs: [] });
133 }}
134 />
135 </ScreenScrollView>
136 </SettingsScreen>
137 );