Open History to see the last commit
1import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
2import { useAtomSet, useAtomValue } from "@effect/atom-react";
3import type { SidebarProjectGroupingMode } from "@t3tools/contracts";
4import { AsyncResult } from "effect/reactivity";
5import { useSafeAreaInsets } from "react-native-safe-area-context";
6
7import { SettingsScreen } from "./components/SettingsScreen";
8import {
9 mobileProjectGroupingModePatch,
10 resolveMobileProjectGroupingSettings,
11} from "../../state/project-grouping";
12import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
13import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow";
14import { SettingsSection } from "./components/SettingsSection";
15import { LanguageSettingsSection } from "./SettingsLanguageRouteScreen";
16import { NewThreadSettingsSection, WorkingSectionSettings } from "./ThreadSettingsSections";
17
18const GROUPING_OPTIONS: ReadonlyArray<{
19 readonly mode: SidebarProjectGroupingMode;
20 readonly label: string;
21 readonly description: string;
22}> = [
23 {
24 mode: "repository",
25 label: "Group by repository",
26 description: "Matching repositories appear as one project.",
27 },
28 {
29 mode: "repository_path",
30 label: "Group by repository path",
31 description: "Keep monorepo paths separate.",
32 },
33 {
34 mode: "separate",
35 label: "Keep separate",
36 description: "Show every workspace as its own project.",
37 },
38];
39
40export function SettingsProjectGroupingRouteScreen() {
41 const insets = useSafeAreaInsets();
42 const preferencesResult = useAtomValue(mobilePreferencesAtom);
43 const savePreferences = useAtomSet(updateMobilePreferencesAtom);
44 const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting;
45 const selectedMode = AsyncResult.isSuccess(preferencesResult)
46 ? resolveMobileProjectGroupingSettings(preferencesResult.value).sidebarProjectGroupingMode
47 : null;
48
49 return (
50 <SettingsScreen title="General">
51 <ScrollView
52 contentInsetAdjustmentBehavior="automatic"
53 showsVerticalScrollIndicator={false}
54 className="flex-1"
55 contentContainerClassName="gap-3 px-5 pt-4"
56 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
57 >
58 <LanguageSettingsSection />
59 <SettingsSection title="Project grouping">
60 {GROUPING_OPTIONS.map((option, index) => (
61 <SettingsChoiceRow
62 key={option.mode}
63 label={option.label}
64 description={option.description}
65 selected={selectedMode === option.mode}
66 separated={index > 0}
67 disabled={!preferencesReady}
68 onPress={() => savePreferences(mobileProjectGroupingModePatch(option.mode))}
69 />
70 ))}
71 </SettingsSection>
72 <WorkingSectionSettings />
73 <NewThreadSettingsSection />
74 </ScrollView>
75 </SettingsScreen>
76 );
77}