Open History to see the last commit
1import type { ThreadReferenceCopyTarget } from "@t3tools/client-runtime/thread-reference";
2import * as Haptics from "expo-haptics";
3
4import { writeComposerContextClipboard } from "./composerContextClipboard";
5import { tryCopyTextWithHaptic } from "./copyTextWithHaptic";
6
7/** Resolves false, after logging why, when the clipboard write fails. */
8export async function copyThreadReference(target: ThreadReferenceCopyTarget): Promise<boolean> {
9 if (!target.fragment)
10 return tryCopyTextWithHaptic(target.value, { target: target.clipboardTarget });
11 try {
12 await writeComposerContextClipboard(target.value, target.fragment);
13 } catch (error) {
14 console.error(`Failed to copy ${target.clipboardTarget} to the clipboard.`, error);
15 return false;
16 }
17 void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light).catch(() => {});
18 return true;
19}