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

SettingsFollowUpRouteScreen.tsx

74 lines3.0 KB

1import { msg, T, useGT, useMessages, Var } from "gt-react-native";
2import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
3import { useAtomSet, useAtomValue } from "@effect/atom-react";
4import { AsyncResult } from "effect/reactivity";
5import { Platform } from "react-native";
6import { useSafeAreaInsets } from "react-native-safe-area-context";
7​
8import { AppText as Text } from "../../components/ui/AppText";
9import { DEFAULT_FOLLOW_UP_BEHAVIOR, type FollowUpBehavior } from "../../lib/followUpBehavior";
10import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
11import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow";
12import { SettingsSection } from "./components/SettingsSection";
13import { SettingsScreen } from "./components/SettingsScreen";
14​
15const FOLLOW_UP_OPTIONS: ReadonlyArray<{
16 readonly behavior: FollowUpBehavior;
17 readonly label: string;
18 readonly description: string;
19}> = [
20 {
21 behavior: "queue",
22 label: msg("Queue", { $context: "verb, follow-up behavior" }),
23 description: msg("Your message waits and runs after the current turn finishes."),
24 },
25 {
26 behavior: "steer",
27 label: msg("Steer", { $context: "verb, follow-up behavior" }),
28 description: msg("Your message reaches the agent right away, changing what it is working on."),
29 },
30];
31​
32export function SettingsFollowUpRouteScreen() {
33 const gt = useGT();
34 const m = useMessages();
35 const insets = useSafeAreaInsets();
36 const preferencesResult = useAtomValue(mobilePreferencesAtom);
37 const savePreferences = useAtomSet(updateMobilePreferencesAtom);
38 const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting;
39 const selectedBehavior = AsyncResult.isSuccess(preferencesResult)
40 ? (preferencesResult.value.followUpBehavior ?? DEFAULT_FOLLOW_UP_BEHAVIOR)
41 : null;
42​
43 const content = (
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={gt("While the agent is running")}>
52 {FOLLOW_UP_OPTIONS.map((option, index) => (
53 <SettingsChoiceRow
54 key={option.behavior}
55 label={m(option.label)}
56 description={m(option.description)}
57 selected={selectedBehavior === option.behavior}
58 separated={index > 0}
59 disabled={!preferencesReady}
60 onPress={() => savePreferences({ followUpBehavior: option.behavior })}
61 />
62 ))}
63 </SettingsSection>
64 <Text className="px-2 text-sm text-foreground-muted">
65 <T>
66 Long-press the send button to use the other option for a single message. With a hardware
67 keyboard, hold <Var>{Platform.OS === "android" ? "Ctrl" : "Command"}</Var> while sending.
68 </T>
69 </Text>
70 </ScrollView>
71 );
72​
73 return <SettingsScreen title={gt("Chat")}>{content}</SettingsScreen>;