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