diff --git a/app/composables/useCopyable.ts b/app/composables/useCopyable.ts index d2eb5d8..0443605 100644 --- a/app/composables/useCopyable.ts +++ b/app/composables/useCopyable.ts @@ -8,12 +8,23 @@ export const useCopyable = ( const icon = ref("i-heroicons-clipboard-document"); const label = ref("Copy"); + const toast = useToast(); + const copy = async () => { - if (typeof valueOrCallback === "function") { - await valueOrCallback(); - } else { - const value = unref(valueOrCallback); - await navigator.clipboard.writeText(value); + try { + if (typeof valueOrCallback === "function") { + await valueOrCallback(); + } else { + const value = unref(valueOrCallback); + await navigator.clipboard.writeText(value); + } + } catch { + toast.add({ + title: "Failed to copy to clipboard", + color: "error", + icon: "i-lucide-circle-x", + }); + return; } icon.value = "i-heroicons-clipboard-document-check";