Open History to see the last commit
1import { T, useGT, useMessages } from "gt-react-native";
2import { TextInput, View } from "react-native";
3
4import { AppText as Text } from "../../../components/ui/AppText";
5import type { ComposerEditorSelection } from "../../../components/ComposerEditor";
6import {
7 ComposerDictationCancelAction,
8 ComposerDictationError,
9 ComposerDictationPrimaryAction,
10 ComposerDictationStartAction,
11 ComposerDictationStatus,
12 ComposerDictationToolbar,
13 useDictationAccessibilityFocus,
14} from "../../voice-input/ComposerDictationControl";
15import type { useVoiceInputController } from "../../voice-input/useVoiceInputController";
16import { resolveVoiceComposerPresentation } from "../../voice-input/voiceInputPresentation";
17
18export function ScheduledTaskPromptField(props: {
19 readonly value: string;
20 readonly onChange: (value: string) => void;
21 readonly selection: ComposerEditorSelection;
22 readonly onChangeSelection: (selection: ComposerEditorSelection) => void;
23 readonly disabled: boolean;
24 readonly voiceInput: ReturnType<typeof useVoiceInputController>;
25}) {
26 const gt = useGT();
27 const m = useMessages();
28 const voice = props.voiceInput;
29 const presentation = resolveVoiceComposerPresentation(voice.state, voice.elapsedSeconds, m);
30 const showsDictation = presentation.statusKind === "active";
31 const showsIdleTrigger = voice.isAvailable && !showsDictation;
32 const {
33 startRef: dictationStartRef,
34 finishRef: dictationFinishRef,
35 focusStart,
36 focusFinish,
37 } = useDictationAccessibilityFocus();
38
39 return (
40 <View className="gap-2 border-t border-border-subtle px-4 py-3">
41 <Text className="text-sm text-foreground-muted">
42 <T>Prompt</T>
43 </Text>
44 <View className="flex-row items-end">
45 <TextInput
46 accessibilityLabel={gt`Prompt`}
47 value={props.value}
48 onChangeText={props.onChange}
49 selection={props.selection}
50 onSelectionChange={({ nativeEvent }) => props.onChangeSelection(nativeEvent.selection)}
51 readOnly={props.disabled || voice.freezesEditor}
52 multiline
53 scrollEnabled
54 textAlignVertical="top"
55 placeholder={gt`What should the agent do each time?`}
56 placeholderTextColorClassName="accent-foreground-muted"
57 className="max-h-40 min-h-24 min-w-0 flex-1 font-sans text-base text-foreground"
58 />
59 {showsIdleTrigger ? (
60 <ComposerDictationStartAction
61 ref={dictationStartRef}
62 state={voice.state}
63 isAvailable={voice.isAvailable}
64 disabled={props.disabled}
65 onStart={voice.start}
66 onCancel={voice.cancel}
67 />
68 ) : null}
69 </View>
70 <ComposerDictationError
71 error={voice.state.phase === "error" ? voice.state.error : null}
72 onDismiss={voice.cancel}
73 />
74 {showsDictation ? (
75 <ComposerDictationToolbar showsDictation onShown={focusFinish} onHidden={focusStart}>
76 <View className="h-11 flex-row items-center">
77 <ComposerDictationCancelAction presentation={presentation} onCancel={voice.cancel} />
78 <ComposerDictationStatus
79 audioLevels={voice.audioLevels}
80 elapsedSeconds={voice.elapsedSeconds}
81 phase={voice.state.phase}
82 presentation={presentation}
83 />
84 <ComposerDictationPrimaryAction
85 ref={dictationFinishRef}
86 state={voice.state}
87 presentation={presentation}
88 isAvailable={voice.isAvailable}
89 disabled={props.disabled}
90 onStart={voice.start}
91 onConfirm={voice.stop}
92 onCancel={voice.cancel}
93 />
94 </View>
95 </ComposerDictationToolbar>
96 ) : null}
97 </View>
98 );
99}