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