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 * as Dialog from "../../components/ui/Dialog"; |
| 2 | import { buildNewThreadLink, type LinkedPrompt } from "@t3tools/shared/promptLinks"; |
| 3 | import { msg } from "gt-react-native"; |
| 4 | |
| 5 | import { m } from "../../i18n/messages"; |
| 6 | |
| 7 | import { tryCopyTextWithHaptic } from "../../lib/copyTextWithHaptic"; |
| 8 | import { |
| 9 | getComposerDraftSnapshot, |
| 10 | setComposerDraftText, |
| 11 | waitForComposerDraftsLoaded, |
| 12 | } from "../../state/use-composer-drafts"; |
| 13 | import { linkedThreadDraftAction } from "./prompt-link-model"; |
| 14 | |
| 15 | export function showPromptLinkNotice(notice: string): void { |
| 16 | Dialog.alert(m(msg("Prompt from a link")), notice); |
| 17 | } |
| 18 | |
| 19 | export async function applyLinkedPromptToThreadDraft( |
| 20 | draftKey: string, |
| 21 | prompt: LinkedPrompt, |
| 22 | notice: string, |
| 23 | ): Promise<void> { |
| 24 | try { |
| 25 | await waitForComposerDraftsLoaded(); |
| 26 | } catch { |
| 27 | Dialog.alert( |
| 28 | m(msg("Could not open link")), |
| 29 | m(msg("Drafts could not be loaded, so the prompt was not added.")), |
| 30 | ); |
| 31 | return; |
| 32 | } |
| 33 | const action = linkedThreadDraftAction(getComposerDraftSnapshot(draftKey).text, prompt.text); |
| 34 | if (action !== "ask") { |
| 35 | if (action === "fill") setComposerDraftText(draftKey, prompt.text); |
| 36 | showPromptLinkNotice(notice); |
| 37 | return; |
| 38 | } |
| 39 | Dialog.alert(m(msg("Linked prompt ready. Replace draft?")), notice, [ |
| 40 | { text: m(msg("Keep mine")), style: "cancel" }, |
| 41 | { |
| 42 | text: m(msg("Replace", { $context: "verb, replaces the draft" })), |
| 43 | onPress: () => setComposerDraftText(draftKey, prompt.text), |
| 44 | }, |
| 45 | ]); |
| 46 | } |
| 47 | |
| 48 | export async function copyPromptLink(prompt: string): Promise<void> { |
| 49 | if (!(await tryCopyTextWithHaptic(buildNewThreadLink({ prompt }), { target: "prompt link" }))) { |
| 50 | Dialog.alert(m(msg("Could not copy")), m(msg("Try again."))); |
| 51 | } |
| 52 | } |