feat(ui): remove validation and more fix button states

This commit is contained in:
Pihkaal
2024-10-02 15:50:21 +02:00
parent e6c7bb2cfb
commit 5fc05ba5e4

32
app.vue
View File

@@ -1,16 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
// TODO: remove error message
// TODO: disable buttons when no qr code is generated (it is currenly possible to download default qr code) // TODO: disable buttons when no qr code is generated (it is currenly possible to download default qr code)
import { renderQRCodeToCanvas } from "@/utils/renderer"; import { renderQRCodeToCanvas } from "@/utils/renderer";
import { IMAGE_FORMATS, LOGOS, settingsSchema } from "@/utils/settings"; import { IMAGE_FORMATS, LOGOS } from "@/utils/settings";
const canvas = ref(null); const canvas = ref(null);
const qrCode = ref("/default.webp"); const form = ref(null);
const qrCode = ref(undefined);
const copyIcon = ref("i-heroicons-clipboard-document"); const copyIcon = ref("i-heroicons-clipboard-document");
const copyLabel = ref("Copy"); const copyLabel = ref("Copy");
const isQRCodeEmpty = computed(() => qrCode.value.length === 0); const isQRCodeEmpty = computed(() => !qrCode.value);
const qrCodeSrc = computed(() => qrCode.value ?? "/default.webp");
const state = reactive({ const state = reactive({
logo: undefined, logo: undefined,
@@ -18,10 +19,14 @@ const state = reactive({
content: undefined, content: undefined,
}); });
const isValidState = computed(
() => state.content && state.logo && state.format,
);
const BASE_API_URL = "http://localhost:3000/api"; const BASE_API_URL = "http://localhost:3000/api";
const apiUrl = computed(() => { const apiUrl = computed(() => {
if (!state.content) return ""; if (!isValidState.value) return "";
const params = new URLSearchParams({ const params = new URLSearchParams({
logo: state.logo, logo: state.logo,
@@ -33,7 +38,9 @@ const apiUrl = computed(() => {
}); });
const updateQRCode = async () => { const updateQRCode = async () => {
if (!state.content) return; await nextTick();
if (!isValidState.value) return;
const logoUrl = `/${state.logo}.png`; const logoUrl = `/${state.logo}.png`;
await renderQRCodeToCanvas(canvas.value, state.content, logoUrl); await renderQRCodeToCanvas(canvas.value, state.content, logoUrl);
@@ -52,7 +59,7 @@ const downloadQRCode = () => {
}; };
const copyQRCode = async () => { const copyQRCode = async () => {
if (state.content.length === 0) return; if (isQRCodeEmpty.value) return;
const logoUrl = `/${state.logo}.png`; const logoUrl = `/${state.logo}.png`;
await renderQRCodeToCanvas(canvas.value, state.content, logoUrl); await renderQRCodeToCanvas(canvas.value, state.content, logoUrl);
@@ -84,10 +91,10 @@ const upperCase = (str: string) => str.toUpperCase();
<div <div
class="w-full h-full max-w-[850px] max-h-[375px] flex justify-between space-x-10" class="w-full h-full max-w-[850px] max-h-[375px] flex justify-between space-x-10"
> >
<img :src="qrCode" class="h-full aspect-square" /> <img :src="qrCodeSrc" class="h-full aspect-square" />
<div class="flex-1 flex flex-col justify-center"> <div class="flex-1 flex flex-col justify-center">
<UForm :schema="settingsSchema" :state="state" class="space-y-4"> <UForm ref="form" :state="state" class="space-y-4">
<UFormGroup <UFormGroup
label="Username or link" label="Username or link"
name="content" name="content"
@@ -139,10 +146,13 @@ const upperCase = (str: string) => str.toUpperCase();
<UInput <UInput
v-model="apiUrl" v-model="apiUrl"
disabled disabled
placeholder="Generate QRCode first" placeholder="Please fill all fields first"
class="w-full" class="w-full"
/> />
<UButton icon="i-heroicons-clipboard-document" /> <UButton
:disabled="isQRCodeEmpty"
icon="i-heroicons-clipboard-document"
/>
</UButtonGroup> </UButtonGroup>
</UFormGroup> </UFormGroup>