feat(renderer): make logo optional

This commit is contained in:
Pihkaal
2024-10-12 17:05:56 +02:00
parent 1dfae1a9f5
commit 7b79354e84
4 changed files with 35 additions and 29 deletions

10
app.vue
View File

@@ -23,7 +23,10 @@ const state = reactive({
});
const isValidState = computed(
() => state.content && state.logo && state.format,
() =>
state.content &&
((state.hasLogo && state.logo) || !state.hasLogo) &&
state.format,
);
const BASE_API_URL = "http://localhost:3000/api";
@@ -32,7 +35,7 @@ const apiUrl = computed(() => {
if (!isValidState.value) return "";
const params = new URLSearchParams({
logo: state.logo,
...(state.hasLogo && { logo: state.logo }),
format: state.format,
content: state.content,
});
@@ -45,7 +48,7 @@ const updateQRCode = async () => {
if (!isValidState.value) return;
const logoUrl = `/logos/${state.logo}.png`;
const logoUrl = state.hasLogo ? `/logos/${state.logo}.png` : undefined;
await renderQRCodeToCanvas(canvas.value, state.content, logoUrl);
qrCode.value = canvas.value.toDataURL(`image/${state.format}`);
@@ -134,6 +137,7 @@ const arrayToUnion = (array: string[]) =>
v-model="state.hasLogo"
class="mb-1.5"
label="Logo"
@change="updateQRCode"
/>
</template>