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

ScheduledTaskPromptField.tsx

87 lines3.4 KB

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