diff --git a/components/Layout/Layout.tsx b/components/Layout/Layout.tsx index 0cc900ce..2003b3c9 100644 --- a/components/Layout/Layout.tsx +++ b/components/Layout/Layout.tsx @@ -130,7 +130,7 @@ export default function Layout({ title, description, children }: LayoutProps) { {/* CONTENT */} -
+

{title}

diff --git a/components/QRScanner/BarebonesQRScanner/index.jsx b/components/QRScanner/BarebonesQRScanner/index.jsx deleted file mode 100644 index d6b5682e..00000000 --- a/components/QRScanner/BarebonesQRScanner/index.jsx +++ /dev/null @@ -1,136 +0,0 @@ -import { useEffect, useRef, useState } from "react"; -import jsQR from "jsqr"; - -function BarebonesQRScanner({ handleCode, pauseRef }) { - const canvasRef = useRef(null); - const videoRef = useRef(null); - const wrapperRef = useRef(null); - const animationFrameRef = useRef(); - const [error, setError] = useState(""); - - useEffect(() => { - const video = videoRef.current; - - navigator.mediaDevices - .getUserMedia({ video: { facingMode: "environment" } }) - .then(function (stream) { - //to prevent AbortError on Firefox in strict mode - if (!video.srcObject) { - setError(""); - video.srcObject = stream; - video.setAttribute("playsinline", true); // required to tell iOS safari we don't want fullscreen - video.play(); - animationFrameRef.current = requestAnimationFrame(tick); - } - }) - .catch((e) => { - setError( - "We couldn't access your camera. Check if your camera is being used by another app and if you gave us permission to use it." - ); - video.srcObject = undefined; - }); - - return () => { - if (video.srcObject) { - video.srcObject.getTracks().forEach((track) => track.stop()); - video.srcObject = undefined; - } - }; - }, []); - - function drawLine(canvas, begin, end, color) { - canvas.beginPath(); - canvas.moveTo(begin.x, begin.y); - canvas.lineTo(end.x, end.y); - canvas.lineWidth = 4; - canvas.strokeStyle = color; - canvas.stroke(); - } - - function parseURL(url) { - try { - const url_obj = new URL(url); - if (url_obj.host !== process.env.NEXT_PUBLIC_QRCODE_HOST) return null; - return url_obj.pathname.split("/").at(-1); - } catch { - return null; - } - } - - function tick() { - const video = videoRef.current; - const canvas = canvasRef.current; - - if (!canvas) { - cancelAnimationFrame(animationFrameRef.current); - return null; - } - - const canvas2D = canvas.getContext("2d"); - - if (video.readyState === video.HAVE_ENOUGH_DATA) { - canvas.hidden = false; - - canvas.height = video.videoHeight; - canvas.width = video.videoWidth; - canvas2D.drawImage(video, 0, 0, canvas.width, canvas.height); - var imageData = canvas2D.getImageData(0, 0, canvas.width, canvas.height); - var code = jsQR(imageData.data, imageData.width, imageData.height, { - inversionAttempts: "dontInvert", - }); - - if (code) { - drawLine( - canvas2D, - code.location.topLeftCorner, - code.location.topRightCorner, - "#78f400" - ); - drawLine( - canvas2D, - code.location.topRightCorner, - code.location.bottomRightCorner, - "#78f400" - ); - drawLine( - canvas2D, - code.location.bottomRightCorner, - code.location.bottomLeftCorner, - "#78f400" - ); - drawLine( - canvas2D, - code.location.bottomLeftCorner, - code.location.topLeftCorner, - "#78f400" - ); - - if (!pauseRef.current) { - const uuid = parseURL(code.data); - - if (uuid) { - pauseRef.current = true; - handleCode(uuid); - } - } - } - } - animationFrameRef.current = requestAnimationFrame(tick); - } - - return ( - <> -