diff --git a/src/lib/components/copy.svelte b/src/lib/components/copy.svelte index 1f0e5dfd8..0e859e79c 100644 --- a/src/lib/components/copy.svelte +++ b/src/lib/components/copy.svelte @@ -2,6 +2,7 @@ import { trackEvent } from '$lib/actions/analytics'; import { tooltip } from '$lib/actions/tooltip'; import { clickOnEnter } from '$lib/helpers/a11y'; + import { copy } from '$lib/helpers/copy'; import { addNotification } from '$lib/stores/notifications'; export let value: string; @@ -9,27 +10,28 @@ let content = 'Click to copy'; - const copy = async () => { - try { - await navigator.clipboard.writeText(value); + async function handleClick() { + const success = await copy(value); + + if (success) { content = 'Copied'; - } catch (error) { + } else { addNotification({ - message: error.message, + message: 'Unable to copy to clipboard', type: 'error' }); - } finally { - if (event) { - trackEvent('click_id_tag', { - name: event - }); - } } - }; + + if (event) { + trackEvent('click_id_tag', { + name: event + }); + } + } setTimeout(() => (content = 'Click to copy'))} use:tooltip={{ diff --git a/src/lib/components/copyInput.svelte b/src/lib/components/copyInput.svelte index 65bd6bb81..b06f1ae36 100644 --- a/src/lib/components/copyInput.svelte +++ b/src/lib/components/copyInput.svelte @@ -1,5 +1,6 @@