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

SettingsProjectGroupingRouteScreen.tsx

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