From dc26ec415f9d14fbca47c9f5543a2c0b5c3a6d60 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Sat, 21 Feb 2026 22:09:50 +0100 Subject: [PATCH] feat: handle and display clipboard error in useCopyable --- app/composables/useCopyable.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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";