Open History to see the last commit
1import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
2import { useAtomSet, useAtomValue } from "@effect/atom-react";
3import type { SidebarProjectGroupingMode } from "@t3tools/contracts";
4import { AsyncResult } from "effect/unstable/reactivity";
5import { Pressable, View } from "react-native";
6import { useSafeAreaInsets } from "react-native-safe-area-context";
7
8import { AppText as Text } from "../../components/AppText";
9import { SymbolView } from "../../components/AppSymbol";
10import { SettingsScreen } from "./components/SettingsScreen";
11import {
12 mobileProjectGroupingModePatch,
13 resolveMobileProjectGroupingSettings,
14} from "../../state/project-grouping";
15import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
16import { SettingsSection } from "./components/SettingsSection";
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="Organization">
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 <SettingsSection title="Project grouping">
59 {GROUPING_OPTIONS.map((option, index) => (
60 <Pressable
61 key={option.mode}
62 accessibilityRole="radio"
63 accessibilityState={{
64 checked: selectedMode === option.mode,
65 disabled: !preferencesReady,
66 }}
67 disabled={!preferencesReady}
68 onPress={() => savePreferences(mobileProjectGroupingModePatch(option.mode))}
69 className={
70 index === 0
71 ? "flex-row items-center gap-4 p-4"
72 : "flex-row items-center gap-4 border-t border-border-subtle p-4"
73 }
74 >
75 <View className="min-w-0 flex-1 gap-1">
76 <Text className="text-lg text-foreground">{option.label}</Text>
77 <Text className="text-sm leading-normal text-foreground-muted">
78 {option.description}
79 </Text>
80 </View>
81 {selectedMode === option.mode ? (
82 <SymbolView
83 name="checkmark"
84 size={18}
85 tintColorClassName={"accent-icon"}
86 type="monochrome"
87 weight="semibold"
88 />
89 ) : null}
90 </Pressable>
91 ))}
92 </SettingsSection>
93 </ScrollView>
94 </SettingsScreen>
95 );
96}