From 3e4f65b19c4a84b07b7e38905f16237f26b535e8 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Sat, 12 Oct 2024 22:32:17 +0200 Subject: [PATCH] feat(ui): show error state and fix copy feature --- app.vue | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app.vue b/app.vue index bfc994f..d74f353 100644 --- a/app.vue +++ b/app.vue @@ -21,6 +21,13 @@ const state = reactive({ content: undefined, }); +const firstBlured = ref(false); + +const stateErrors = computed(() => ({ + content: firstBlured.value && !state.content, + logo: firstBlured.value && state.hasLogo && !state.logo, +})); + const isValidState = computed( () => state.content && @@ -77,10 +84,10 @@ const downloadQRCode = () => { const copyQRCode = async () => { if (isQRCodeEmpty.value) return; - const logoUrl = `/logos/${state.logo}.png`; - await renderQRCodeToCanvas(canvas.value, state.content, logoUrl); + const logoUrl = state.hasLogo ? `/logos/${state.logo}.png` : undefined; + const canvas = await renderQRCodeToCanvas(state.content, logoUrl); - const qrCode = canvas.value.toDataURL(`image/png`); + const qrCode = canvas.toDataURL(`image/png`); const blob = await (await fetch(qrCode)).blob(); const item = new ClipboardItem({ "image/png": blob }); @@ -120,22 +127,25 @@ const arrayToUnion = (array: string[]) => - + @@ -148,6 +158,7 @@ const arrayToUnion = (array: string[]) => searchable clear-search-on-close @change="updateQRCode" + @blur="firstBlured = true" >