The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { VoiceInputState } from "@t3tools/client-runtime/voice-input"; |
| 2 | import { msg } from "gt-react-native"; |
| 3 | |
| 4 | import { m, type MessageResolver } from "../../i18n/messages"; |
| 5 | |
| 6 | export type VoiceComposerPresentation = { |
| 7 | readonly leadingAction: "cancel" | null; |
| 8 | readonly trailingAction: "mic" | "confirm"; |
| 9 | readonly showsSend: boolean; |
| 10 | readonly statusKind: "active" | "error" | null; |
| 11 | readonly statusLabel: string | null; |
| 12 | readonly confirmationEnabled: boolean; |
| 13 | }; |
| 14 | |
| 15 | export function resolveVoiceComposerPresentation( |
| 16 | state: VoiceInputState, |
| 17 | elapsedSeconds: number, |
| 18 | resolve: MessageResolver = m, |
| 19 | ): VoiceComposerPresentation { |
| 20 | switch (state.phase) { |
| 21 | case "idle": |
| 22 | return { |
| 23 | leadingAction: null, |
| 24 | trailingAction: "mic", |
| 25 | showsSend: true, |
| 26 | statusKind: null, |
| 27 | statusLabel: null, |
| 28 | confirmationEnabled: false, |
| 29 | }; |
| 30 | case "error": |
| 31 | return { |
| 32 | leadingAction: null, |
| 33 | trailingAction: "mic", |
| 34 | showsSend: true, |
| 35 | statusKind: "error", |
| 36 | statusLabel: state.error, |
| 37 | confirmationEnabled: false, |
| 38 | }; |
| 39 | case "preparing": |
| 40 | return { |
| 41 | leadingAction: "cancel", |
| 42 | trailingAction: "confirm", |
| 43 | showsSend: false, |
| 44 | statusKind: "active", |
| 45 | statusLabel: resolve(msg("Preparing", { $context: "voice input status" })), |
| 46 | confirmationEnabled: false, |
| 47 | }; |
| 48 | case "recording": { |
| 49 | const seconds = Math.max(0, Math.floor(elapsedSeconds)); |
| 50 | return { |
| 51 | leadingAction: "cancel", |
| 52 | trailingAction: "confirm", |
| 53 | showsSend: false, |
| 54 | statusKind: "active", |
| 55 | statusLabel: resolve( |
| 56 | msg("Recording {time}", { |
| 57 | time: `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`, |
| 58 | }), |
| 59 | ), |
| 60 | confirmationEnabled: true, |
| 61 | }; |
| 62 | } |
| 63 | case "transcribing": |
| 64 | case "post-processing": |
| 65 | return { |
| 66 | leadingAction: "cancel", |
| 67 | trailingAction: "confirm", |
| 68 | showsSend: false, |
| 69 | statusKind: "active", |
| 70 | statusLabel: resolve(msg("Transcribing", { $context: "voice input status" })), |
| 71 | confirmationEnabled: false, |
| 72 | }; |
| 73 | } |
| 74 | } |