From 1e2d774710dd5af47abbcc697072aee7838e0925 Mon Sep 17 00:00:00 2001 From: Toni Kangas Date: Mon, 5 May 2025 01:09:51 +0300 Subject: [PATCH] Copy link to clipboard when clicking the QR code --- front-end/src/views/Share.svelte | 58 +++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/front-end/src/views/Share.svelte b/front-end/src/views/Share.svelte index 8c40171..1d18a71 100644 --- a/front-end/src/views/Share.svelte +++ b/front-end/src/views/Share.svelte @@ -10,6 +10,10 @@ let { question }: Props = $props(); + let copied = $state(false); + + const url = `${window.location.origin}/${question.key}`; + $effect(() => { var style = window.getComputedStyle(document.documentElement); const light = style.getPropertyValue("--color-bg"); @@ -17,7 +21,7 @@ const rem = parseFloat(style.fontSize); const canvas = document.getElementById("qrcode") as HTMLCanvasElement; - QRCode.toCanvas(canvas, `${window.location.origin}/${question.key}`, { + QRCode.toCanvas(canvas, url, { color: { dark, light, @@ -26,20 +30,66 @@ width: 12 * rem, }); }); + + const copyLink = async () => { + try { + await navigator.clipboard.writeText(url); + copied = true; + setTimeout(() => { + copied = false; + }, 1500); + } catch { + /* Ignore error */ + } + };

Scan the QR code to open the feedback form.

- +