Skip to content

Commit

Permalink
hide scanner after scan
Browse files Browse the repository at this point in the history
  • Loading branch information
squi-ddy committed Oct 22, 2024
1 parent 973dc39 commit 2824f78
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion frontend/src/routes/admin_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ export default function AdminPage() {
}}
>
<Typography variant="body1">Administration</Typography>
<Button variant="contained" size="large" startIcon={!showScanner && <QrCodeScannerIcon />} onClick={() => setShowScanner((s) => !s)}>{showScanner ? "Stop Scanning" : "Scan Student's QR Code"}</Button>
<Button variant="contained" size="large" startIcon={!showScanner && <QrCodeScannerIcon />} onClick={() => {
if (showScanner) {
setShowScanner(false);
} else {
setShowScanner(true);
setTopup(null);
}
}}>{showScanner ? "Stop Scanning" : "Scan Student's QR Code"}</Button>
{showScanner && <Scanner onScan={async (code) => {
const resp = await getTopup(code[0].rawValue);
if (resp === null) {
alert("Failed to fetch topup details");
return;
}
setShowScanner(false);
setTopup(resp);
}} formats={["qr_code"]} classNames={{container: "scanner-container"}} />}

Expand Down

0 comments on commit 2824f78

Please sign in to comment.