Open History to see the last commit
1import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
2import { useAuth, useUser } from "@clerk/expo";
3import { useNavigation } from "@react-navigation/native";
4import { Platform, View } from "react-native";
5import { deriveProjectGroupLabel } from "@t3tools/client-runtime/state/project-grouping";
6import { useSafeAreaInsets } from "react-native-safe-area-context";
7
8import { hasCloudPublicConfig } from "../cloud/publicConfig";
9import { WorkspaceSidebarToolbar } from "../layout/workspace-sidebar-toolbar";
10import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
11import { SettingsRow } from "./components/SettingsRow";
12import { SettingsSection } from "./components/SettingsSection";
13import { SettingsScreen } from "./components/SettingsScreen";
14import {
15 AndroidSettingsEnvironmentFilter,
16 SettingsEnvironmentFilterHeader,
17} from "./components/SettingsEnvironmentFilterHeader";
18import { useSettingsEnvironmentFilter } from "./settings-environment-filter";
19
20export function SettingsRouteScreen() {
21 const content = hasCloudPublicConfig() ? (
22 <ConfiguredSettingsRouteScreen />
23 ) : (
24 <LocalSettingsRouteScreen />
25 );
26
27 return (
28 <>
29 <WorkspaceSidebarToolbar />
30 <SettingsEnvironmentFilterHeader closeSettings />
31 {Platform.OS === "android" ? (
32 <SettingsScreen title="Settings" trailing={<AndroidSettingsEnvironmentFilter />}>
33 {content}
34 </SettingsScreen>
35 ) : (
36 content
37 )}
38 </>
39 );
40}
41
42function ConfiguredSettingsRouteScreen() {
43 const insets = useSafeAreaInsets();
44 const navigation = useNavigation();
45 const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false });
46 const { user } = useUser();
47 const { savedConnectionsById } = useSavedRemoteConnections();
48 const accountLabel = !isLoaded
49 ? "Checking"
50 : !isSignedIn
51 ? "Sign in"
52 : (user?.primaryEmailAddress?.emailAddress ?? "Signed in");
53
54 return (
55 <View collapsable={false} className="flex-1 bg-sheet">
56 <ScrollView
57 contentInsetAdjustmentBehavior="automatic"
58 showsVerticalScrollIndicator={false}
59 className="flex-1"
60 contentContainerClassName="gap-4 px-5 pt-4"
61 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
62 >
63 <SettingsSection title="Connections">
64 <SettingsRow
65 icon="person.crop.circle"
66 label="T3 Account"
67 value={accountLabel}
68 disabled={!isLoaded}
69 onPress={() => navigation.navigate("SettingsSheet", { screen: "SettingsAuth" })}
70 />
71 <SettingsRow
72 icon="desktopcomputer"
73 label="Environments"
74 value={`${Object.keys(savedConnectionsById).length}`}
75 valuePosition="trailing"
76 target="SettingsEnvironments"
77 />
78 <SettingsRow icon="bell.badge" label="Notifications" target="SettingsNotifications" />
79 </SettingsSection>
80
81 <SettingsIndexSections />
82 </ScrollView>
83 </View>
84 );
85}
86
87function LocalSettingsRouteScreen() {
88 const insets = useSafeAreaInsets();
89 const { savedConnectionsById } = useSavedRemoteConnections();
90 const environmentCount = Object.keys(savedConnectionsById).length;
91
92 return (
93 <View collapsable={false} className="flex-1 bg-sheet">
94 <ScrollView
95 contentInsetAdjustmentBehavior="automatic"
96 showsVerticalScrollIndicator={false}
97 className="flex-1"
98 contentContainerClassName="gap-4 px-5 pt-4"
99 contentContainerStyle={{
100 paddingBottom: Math.max(insets.bottom, 18) + 18,
101 }}
102 >
103 <SettingsSection title="Connections">
104 <SettingsRow
105 icon="desktopcomputer"
106 label="Environments"
107 value={`${environmentCount}`}
108 valuePosition="trailing"
109 target="SettingsEnvironments"
110 />
111 </SettingsSection>
112
113 <SettingsIndexSections />
114 </ScrollView>
115 </View>
116 );
117}
118
119function SettingsIndexSections() {
120 const { selectedTargets, projectGroups, selectedProjectKey } = useSettingsEnvironmentFilter();
121 const noServerTargets = selectedTargets.length === 0;
122 const selectedProject = projectGroups.find((group) => group.key === selectedProjectKey);
123 const scopedProjectMembers =
124 selectedProject?.members
125 .map((member) => member.project)
126 .filter((project) =>
127 selectedTargets.some((target) => target.environmentId === project.environmentId),
128 ) ?? [];
129 const projectLabel =
130 scopedProjectMembers.length > 0
131 ? deriveProjectGroupLabel({
132 representative: scopedProjectMembers[0]!,
133 members: scopedProjectMembers,
134 })
135 : (selectedProject?.label ?? "Unavailable project");
136 return (
137 <>
138 <SettingsSection title="Interface">
139 <SettingsRow icon="paintbrush" label="Appearance" target="SettingsAppearance" />
140 {Platform.OS === "ios" ? (
141 <SettingsRow icon="keyboard" label="Keyboard" target="SettingsKeyboard" />
142 ) : null}
143 </SettingsSection>
144
145 <SettingsSection title="Projects & threads">
146 {selectedProjectKey !== null ? (
147 <SettingsRow
148 icon="folder"
149 label="Overview"
150 value={projectLabel}
151 target="SettingsProjectOverview"
152 />
153 ) : null}
154 <SettingsRow icon="folder" label="Organization" target="SettingsOrganization" />
155 <SettingsRow icon="text.bubble" label="Thread behavior" target="SettingsThreads" />
156 <SettingsRow icon="archivebox" label="Archived Threads" target="SettingsArchive" />
157 </SettingsSection>
158
159 <SettingsSection title="Server settings">
160 <SettingsRow
161 icon="text.bubble"
162 label="New threads"
163 target="SettingsEnvironmentNewThreads"
164 disabled={noServerTargets}
165 />
166 <SettingsRow
167 icon="arrow.triangle.branch"
168 label="Source control"
169 target="SettingsEnvironmentSourceControl"
170 disabled={noServerTargets}
171 />
172 <SettingsRow
173 icon="text.alignleft"
174 label="Agent behavior"
175 target="SettingsEnvironmentAgentBehavior"
176 disabled={noServerTargets}
177 />
178 <SettingsRow
179 icon="arrow.clockwise"
180 label="Maintenance"
181 target="SettingsEnvironmentMaintenance"
182 disabled={noServerTargets}
183 />
184 </SettingsSection>
185
186 <SettingsSection title="App">
187 <SettingsRow icon="chart.bar.xaxis" label="Usage" target="SettingsUsage" />
188 <SettingsRow icon="info.circle" label="About T3 Code" target="SettingsAbout" />
189 </SettingsSection>
190 </>
191 );
192}