-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement badge barcode scanning (#374)
* Install `html5-qrcode` for scanning barcodes * Store and provide badge number for participants - Update check-in POST request to send badge number - Update check-in endpoint to store badge number - Update participants endpoint to provide badge numbers * Implement badge scanner with html5-qrcode - Still some weird `useEffect` issues with scanner opening twice
- Loading branch information
Showing
7 changed files
with
135 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useEffect } from "react"; | ||
|
||
import { | ||
Html5QrcodeScanner, | ||
QrcodeErrorCallback, | ||
QrcodeSuccessCallback, | ||
} from "html5-qrcode"; | ||
|
||
const scannerRegionId = "badge-scanner-full-region"; | ||
|
||
interface BadgeScannerProps { | ||
fps?: number; | ||
qrbox?: number; | ||
aspectRatio?: number; | ||
disableFlip?: boolean; | ||
verbose?: boolean; | ||
onSuccess: QrcodeSuccessCallback; | ||
onError: QrcodeErrorCallback; | ||
} | ||
|
||
function BadgeScanner(props: BadgeScannerProps) { | ||
useEffect(() => { | ||
const { | ||
fps, | ||
qrbox, | ||
aspectRatio, | ||
disableFlip, | ||
verbose, | ||
onSuccess, | ||
onError, | ||
} = props; | ||
|
||
const html5QrcodeScanner = new Html5QrcodeScanner( | ||
scannerRegionId, | ||
{ | ||
fps: fps ?? 5, | ||
qrbox: qrbox ?? 300, | ||
aspectRatio: aspectRatio ?? 1, | ||
disableFlip: disableFlip ?? true, | ||
}, | ||
verbose ?? false, | ||
); | ||
html5QrcodeScanner.render(onSuccess, onError); | ||
|
||
// Clean up when unmount | ||
return () => { | ||
html5QrcodeScanner.clear().catch((error) => { | ||
console.error("Failed to clear html5QrcodeScanner. ", error); | ||
}); | ||
}; | ||
}, [props]); | ||
|
||
return <div id={scannerRegionId} />; | ||
} | ||
|
||
export default BadgeScanner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.