Skip to content

Commit 44f796f

Browse files
committed
react: improve result display of barcode & vin result toast
1 parent 823c4d3 commit 44f796f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

react-js/src/pages/BarcodeScannerPage.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ export default function BarcodeScannerPage() {
1414
const [toast, setToast] = React.useState<string | undefined>(undefined);
1515

1616
const onBarcodesDetected = (result: BarcodeScannerResultWithSize) => {
17-
setToast(JSON.stringify(result));
17+
18+
let text = "";
19+
result.barcodes.forEach((barcode) => {
20+
text += `${barcode.text} (${barcode.format})\n`;
21+
});
22+
setToast(text);
1823
};
1924

2025
useEffect(() => {

react-js/src/pages/VinScannerPage.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ export default function VINScannerPage() {
1010
const [toast, setToast] = React.useState<string | undefined>(undefined);
1111

1212
const onTextDetected = (result: VinScannerResult) => {
13-
setToast(JSON.stringify(result));
13+
14+
let text = "";
15+
16+
if (result.barcodeResult.extractedVIN) {
17+
text += `Barcode: ${result.barcodeResult.extractedVIN}\n`;
18+
}
19+
if (result.textResult.rawText) {
20+
text += `Text: ${result.textResult.rawText} (${result.textResult.confidence.toFixed(2)}%)\n`;
21+
}
22+
setToast(text);
1423
};
1524

1625
useEffect(() => {

0 commit comments

Comments
 (0)