The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { msg, T, useGT, useMessages } from "gt-react-native"; |
| 2 | import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView"; |
| 3 | import { useAtomValue } from "@effect/atom-react"; |
| 4 | import { AsyncResult } from "effect/reactivity"; |
| 5 | import { Platform } from "react-native"; |
| 6 | import { useSafeAreaInsets } from "react-native-safe-area-context"; |
| 7 | |
| 8 | import { AppText as Text } from "../../components/ui/AppText"; |
| 9 | import { |
| 10 | DEFAULT_COMPOSER_ENTER_BEHAVIOR, |
| 11 | type ComposerEnterBehavior, |
| 12 | } from "../../lib/composerEnterBehavior"; |
| 13 | import { mobilePreferencesAtom, saveMobilePreferences } from "../../state/preferences"; |
| 14 | import { useAtomCommand } from "../../state/use-atom-command"; |
| 15 | import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow"; |
| 16 | import { SettingsScreen } from "./components/SettingsScreen"; |
| 17 | import { SettingsSection } from "./components/SettingsSection"; |
| 18 | |
| 19 | const SEND_MODIFIER = Platform.OS === "android" ? "Ctrl" : "Command"; |
| 20 | |
| 21 | const ENTER_BEHAVIOR_OPTIONS: ReadonlyArray<{ |
| 22 | readonly behavior: ComposerEnterBehavior; |
| 23 | readonly label: string; |
| 24 | readonly description: string; |
| 25 | }> = [ |
| 26 | { |
| 27 | behavior: "send", |
| 28 | label: msg("Send message"), |
| 29 | description: msg("{returnKey} sends the message. {shiftReturn} inserts a new line.", { |
| 30 | returnKey: "Return", |
| 31 | shiftReturn: "Shift-Return", |
| 32 | }), |
| 33 | }, |
| 34 | { |
| 35 | behavior: "newline", |
| 36 | label: msg("Insert new line"), |
| 37 | description: msg("{returnKey} inserts a new line. {sendKeys} sends the message.", { |
| 38 | returnKey: "Return", |
| 39 | sendKeys: `${SEND_MODIFIER}-Return`, |
| 40 | }), |
| 41 | }, |
| 42 | ]; |
| 43 | |
| 44 | export function SettingsKeyboardRouteScreen() { |
| 45 | const gt = useGT(); |
| 46 | const m = useMessages(); |
| 47 | const insets = useSafeAreaInsets(); |
| 48 | const preferencesResult = useAtomValue(mobilePreferencesAtom); |
| 49 | const savePreferences = useAtomCommand(saveMobilePreferences); |
| 50 | const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting; |
| 51 | const selectedBehavior = AsyncResult.isSuccess(preferencesResult) |
| 52 | ? (preferencesResult.value.composerEnterBehavior ?? DEFAULT_COMPOSER_ENTER_BEHAVIOR) |
| 53 | : null; |
| 54 | |
| 55 | return ( |
| 56 | <SettingsScreen title={gt("Keyboard")}> |
| 57 | <ScrollView |
| 58 | contentInsetAdjustmentBehavior="automatic" |
| 59 | showsVerticalScrollIndicator={false} |
| 60 | className="flex-1" |
| 61 | contentContainerClassName="gap-3 px-5 pt-4" |
| 62 | contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }} |
| 63 | > |
| 64 | <SettingsSection title={gt("Return key")}> |
| 65 | {ENTER_BEHAVIOR_OPTIONS.map((option, index) => ( |
| 66 | <SettingsChoiceRow |
| 67 | key={option.behavior} |
| 68 | label={m(option.label)} |
| 69 | description={m(option.description)} |
| 70 | selected={selectedBehavior === option.behavior} |
| 71 | separated={index > 0} |
| 72 | disabled={!preferencesReady} |
| 73 | onPress={() => { |
| 74 | void savePreferences({ composerEnterBehavior: option.behavior }); |
| 75 | }} |
| 76 | /> |
| 77 | ))} |
| 78 | </SettingsSection> |
| 79 | <Text className="px-2 text-sm text-foreground-muted"> |
| 80 | <T>Applies to the composer when a hardware keyboard is connected.</T> |
| 81 | </Text> |
| 82 | </ScrollView> |
| 83 | </SettingsScreen> |
| 84 | ); |
| 85 | } |