Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SettingsProjectGroupingRouteScreen.tsx

106 lines4.0 KB

1import { useAtomSet, useAtomValue } from "@effect/atom-react";
2import { useNavigation } from "@react-navigation/native";
3import type { SidebarProjectGroupingMode } from "@t3tools/contracts";
4import { AsyncResult } from "effect/unstable/reactivity";
5import { Platform, Pressable, ScrollView, View } from "react-native";
6import { useSafeAreaInsets } from "react-native-safe-area-context";
7​
8import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
9import { AppText as Text } from "../../components/AppText";
10import { SymbolView } from "../../components/AppSymbol";
11import { useThemeColor } from "../../lib/useThemeColor";
12import { NativeStackScreenOptions } from "../../native/StackHeader";
13import {
14 mobileProjectGroupingModePatch,
15 resolveMobileProjectGroupingSettings,
16} from "../../state/project-grouping";
17import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
18import { SettingsSection } from "./components/SettingsSection";
19​
20const GROUPING_OPTIONS: ReadonlyArray<{
21 readonly mode: SidebarProjectGroupingMode;
22 readonly label: string;
23 readonly description: string;
24}> = [
25 {
26 mode: "repository",
27 label: "Group by repository",
28 description: "Matching repositories appear as one project.",
29 },
30 {
31 mode: "repository_path",
32 label: "Group by repository path",
33 description: "Keep monorepo paths separate.",
34 },
35 {
36 mode: "separate",
37 label: "Keep separate",
38 description: "Show every workspace as its own project.",
39 },
40];
41​
42export function SettingsProjectGroupingRouteScreen() {
43 const navigation = useNavigation();
44 const insets = useSafeAreaInsets();
45 const checkmarkColor = useThemeColor("--color-icon");
46 const preferencesResult = useAtomValue(mobilePreferencesAtom);
47 const savePreferences = useAtomSet(updateMobilePreferencesAtom);
48 const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting;
49 const selectedMode = AsyncResult.isSuccess(preferencesResult)
50 ? resolveMobileProjectGroupingSettings(preferencesResult.value).sidebarProjectGroupingMode
51 : null;
52​
53 return (
54 <View collapsable={false} className="flex-1 bg-sheet">
55 {Platform.OS === "android" ? (
56 <>
57 <NativeStackScreenOptions options={{ headerShown: false }} />
58 <AndroidScreenHeader title="Project Grouping" onBack={() => navigation.goBack()} />
59 </>
60 ) : null}
61 <ScrollView
62 contentInsetAdjustmentBehavior="automatic"
63 showsVerticalScrollIndicator={false}
64 className="flex-1"
65 contentContainerClassName="gap-3 px-5 pt-4"
66 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
67 >
68 <SettingsSection title="Default grouping">
69 {GROUPING_OPTIONS.map((option, index) => (
70 <Pressable
71 key={option.mode}
72 accessibilityRole="radio"
73 accessibilityState={{
74 checked: selectedMode === option.mode,
75 disabled: !preferencesReady,
76 }}
77 disabled={!preferencesReady}
78 onPress={() => savePreferences(mobileProjectGroupingModePatch(option.mode))}
79 className={
80 index === 0
81 ? "flex-row items-center gap-4 p-4"
82 : "flex-row items-center gap-4 border-t border-border-subtle p-4"
83 }
84 >
85 <View className="min-w-0 flex-1 gap-1">
86 <Text className="text-lg text-foreground">{option.label}</Text>
87 <Text className="text-sm leading-normal text-foreground-muted">
88 {option.description}
89 </Text>
90 </View>
91 {selectedMode === option.mode ? (
92 <SymbolView
93 name="checkmark"
94 size={18}
95 tintColor={checkmarkColor}
96 type="monochrome"
97 weight="semibold"
98 />
99 ) : null}
100 </Pressable>
101 ))}
102 </SettingsSection>
103 </ScrollView>
104 </View>
105 );