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

SettingsKeyboardRouteScreen.tsx

70 lines2.7 KB

1import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
2import { useAtomSet, useAtomValue } from "@effect/atom-react";
3import { AsyncResult } from "effect/reactivity";
4import { useSafeAreaInsets } from "react-native-safe-area-context";
5​
6import { AppText as Text } from "../../components/ui/AppText";
7import {
8 DEFAULT_COMPOSER_ENTER_BEHAVIOR,
9 type ComposerEnterBehavior,
10} from "../../lib/composerEnterBehavior";
11import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
12import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow";
13import { SettingsScreen } from "./components/SettingsScreen";
14import { SettingsSection } from "./components/SettingsSection";
15​
16const ENTER_BEHAVIOR_OPTIONS: ReadonlyArray<{
17 readonly behavior: ComposerEnterBehavior;
18 readonly label: string;
19 readonly description: string;
20}> = [
21 {
22 behavior: "send",
23 label: "Send message",
24 description: "Return sends the message. Shift-Return inserts a new line.",
25 },
26 {
27 behavior: "newline",
28 label: "Insert new line",
29 description: "Return inserts a new line. Command-Return sends the message.",
30 },
31];
32​
33export function SettingsKeyboardRouteScreen() {
34 const insets = useSafeAreaInsets();
35 const preferencesResult = useAtomValue(mobilePreferencesAtom);
36 const savePreferences = useAtomSet(updateMobilePreferencesAtom);
37 const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting;
38 const selectedBehavior = AsyncResult.isSuccess(preferencesResult)
39 ? (preferencesResult.value.composerEnterBehavior ?? DEFAULT_COMPOSER_ENTER_BEHAVIOR)
40 : null;
41​
42 return (
43 <SettingsScreen title="Keyboard">
44 <ScrollView
45 contentInsetAdjustmentBehavior="automatic"
46 showsVerticalScrollIndicator={false}
47 className="flex-1"
48 contentContainerClassName="gap-3 px-5 pt-4"
49 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
50 >
51 <SettingsSection title="Return key">
52 {ENTER_BEHAVIOR_OPTIONS.map((option, index) => (
53 <SettingsChoiceRow
54 key={option.behavior}
55 label={option.label}
56 description={option.description}
57 selected={selectedBehavior === option.behavior}
58 separated={index > 0}
59 disabled={!preferencesReady}
60 onPress={() => savePreferences({ composerEnterBehavior: option.behavior })}
61 />
62 ))}
63 </SettingsSection>
64 <Text className="px-2 text-sm text-foreground-muted">
65 Applies to the composer when a hardware keyboard is connected.
66 </Text>
67 </ScrollView>
68 </SettingsScreen>
69 );