From 69370f10496d64bb73f0c7b4849492ee5859a406 Mon Sep 17 00:00:00 2001 From: theoleuthardt Date: Fri, 21 Feb 2025 15:19:44 +0100 Subject: [PATCH] fix: QRCode variable name + clear button and conditional rendering --- frontend/src/app/qr-code-generator/page.tsx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/qr-code-generator/page.tsx b/frontend/src/app/qr-code-generator/page.tsx index 0b2a82b..c179264 100644 --- a/frontend/src/app/qr-code-generator/page.tsx +++ b/frontend/src/app/qr-code-generator/page.tsx @@ -7,7 +7,7 @@ import Image from "next/image"; export default function QrCodeGenerator() { const [loading, setLoading] = useState(false); - const [qrcode, setQRCode] = useState(null); + const [QRCodeURL, setQRCodeURL] = useState(null); const downloadImage = (dataUrl: string) => { const link = document.createElement("a"); @@ -33,7 +33,7 @@ export default function QrCodeGenerator() { "Content-Type": "application/json", }, body: JSON.stringify({ - data: textInput, + qrcodeContent: textInput, }), }, ); @@ -43,9 +43,8 @@ export default function QrCodeGenerator() { } const data = await response.json(); - console.log("Data:", data); if (data.qrCode) { - setQRCode(data.qrCode); + setQRCodeURL(data.qrCode); downloadImage(data.qrCode); } } catch (error) { @@ -56,6 +55,12 @@ export default function QrCodeGenerator() { } }; + function clearInputAndQRCode() { + setQRCodeURL(""); + const data = document.getElementById("data") as HTMLInputElement; + data.value = ""; + } + return (
@@ -82,14 +87,16 @@ export default function QrCodeGenerator() { } onClick={generateQRCode} /> +
- {qrcode && ( + {QRCodeURL && ( QR Code )}