diff --git a/package-lock.json b/package-lock.json index a7123bf..c79271c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "framer-motion": "^8.5.4", "nostr-react": "^0.6.4", "nostr-tools": "^1.3.2", + "qr-scanner": "^1.4.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-linkify": "1.0.0-alpha", @@ -2433,6 +2434,11 @@ "integrity": "sha512-5EWrvLmglK+imbCJY0+INViFWUHg1AHel1sq4ZVSfdcNqGy9Edv3UB9IIzzg+xPaUcAgZYcfVs2fBcwDeZzU0A==", "dev": true }, + "node_modules/@types/offscreencanvas": { + "version": "2019.7.0", + "resolved": "https://registry.npmjs.org/@types/offscreencanvas/-/offscreencanvas-2019.7.0.tgz", + "integrity": "sha512-PGcyveRIpL1XIqK8eBsmRBt76eFgtzuPiSTyKHZxnGemp2yzGzWpjYKAfK3wIMiU7eH+851yEpiuP8JZerTmWg==" + }, "node_modules/@types/prop-types": { "version": "15.7.5", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", @@ -4609,6 +4615,14 @@ "node": ">=6" } }, + "node_modules/qr-scanner": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/qr-scanner/-/qr-scanner-1.4.2.tgz", + "integrity": "sha512-kV1yQUe2FENvn59tMZW6mOVfpq9mGxGf8l6+EGaXUOd4RBOLg7tRC83OrirM5AtDvZRpdjdlXURsHreAOSPOUw==", + "dependencies": { + "@types/offscreencanvas": "^2019.6.4" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", diff --git a/package.json b/package.json index da4e349..104dc8e 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "framer-motion": "^8.5.4", "nostr-react": "^0.6.4", "nostr-tools": "^1.3.2", + "qr-scanner": "^1.4.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-linkify": "1.0.0-alpha", diff --git a/src/App.tsx b/src/App.tsx index 83fc0aa..f6ae8d2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,7 @@ import Join from "@/routes/Join"; import Layout from "@/components/Layout"; import SecretWaitlistSkipper from "@/routes/SecretWaitlistSkipper"; import Home from "@/routes/Home"; +import Scanner from "@/routes/Scanner"; function App() { let active = localStorage.getItem('active') || ""; @@ -13,10 +14,10 @@ function App() { {/* globals such as header will go here */} - {/* } /> */} }> : } /> } /> + } /> diff --git a/src/components/Reader.tsx b/src/components/Reader.tsx new file mode 100644 index 0000000..4db809f --- /dev/null +++ b/src/components/Reader.tsx @@ -0,0 +1,37 @@ +import QrScanner from 'qr-scanner'; +import { useEffect, useRef } from "react"; + +export default function Scanner({ onResult }: { onResult: (result: string) => void }) { + const container = useRef(null); + + useEffect(() => { + let scanner: QrScanner | null; + if (container.current) { + scanner = new QrScanner( + container.current, + (result) => { + onResult(result.data); + }, + { + returnDetailedScanResult: true, + + } + ); + + scanner.start(); + } + + return () => { + scanner?.destroy(); + scanner = null; + } + }, [onResult]); + + return ( + <> + + + + > + ); +} diff --git a/src/index.css b/src/index.css index ff9729e..b9e26ec 100644 --- a/src/index.css +++ b/src/index.css @@ -3,12 +3,20 @@ @tailwind utilities; body { - @apply text-white; - @apply bg-fixed bg-no-repeat bg-gradient-to-b from-black to-[#0b215b] bg-black; + @apply text-white bg-black; + @apply bg-fixed bg-no-repeat bg-gradient-to-b from-black to-[#0b215b]; overscroll-behavior-y: none; min-height: 100.3%; } +.bg-gradient { + @apply bg-fixed bg-no-repeat bg-gradient-to-b from-black to-[#0b215b]; +} + +.bg-gray { + @apply bg-fixed bg-no-repeat bg-gradient-to-b from-[hsl(224,5%,5%)] to-[hsl(224,5%,20%)]; +} + .react-modal-sheet-container { @apply !bg-[#262626]; } @@ -16,3 +24,19 @@ body { a { @apply underline decoration-light-text hover:decoration-white; } + +#video-container { + position: relative; + width: max-content; + height: max-content; + overflow: hidden; +} + +#video-container .scan-region-highlight { + border-radius: 30px; + outline: rgba(0, 0, 0, 0.25) solid 50vmax; +} + +#video-container .scan-region-highlight-svg { + display: none; +} diff --git a/src/routes/Home.tsx b/src/routes/Home.tsx index 14256d3..1111aab 100644 --- a/src/routes/Home.tsx +++ b/src/routes/Home.tsx @@ -5,6 +5,7 @@ import mutiny_m from '@/assets/m.svg'; import scan from '@/assets/scan.svg'; import settings from '@/assets/settings.svg'; import send from '@/assets/send.svg'; +import { Link } from 'react-router-dom'; function ActivityItem() { return ( @@ -89,17 +90,16 @@ function App() { - + - + + + - + - {/* home */} - {/* scan */} - {/* settings */} diff --git a/src/routes/Scanner.tsx b/src/routes/Scanner.tsx new file mode 100644 index 0000000..5aa0f70 --- /dev/null +++ b/src/routes/Scanner.tsx @@ -0,0 +1,48 @@ +import { useNavigate } from "react-router-dom"; +import button from "@/styles/button"; + +import { useState } from "react"; +import Reader from "@/components/Reader"; + +export default function Scanner() { + const navigate = useNavigate(); + + const [scanResult, setScanResult] = useState(null); + + function onResult(result: string) { + setScanResult(result); + } + + function exit() { + navigate("/") + } + + return ( + <> + {scanResult ? + + + + Scan Result + + {scanResult} + + : + } + + {!scanResult && + <> + Paste Something + Cancel + > + } + {scanResult && + <> + setScanResult(null)}>Try Again + Cancel + > + } + + > + ); +} \ No newline at end of file
{scanResult}