All files / components BarcodeScannerView.tsx

16.66% Statements 1/6
0% Branches 0/8
0% Functions 0/2
16.66% Lines 1/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                1x                                            
import { useEffect } from 'react';
import { Alert, Card, CardContent, Typography } from '@mui/material';
import { useBarcodeScanner } from '../hooks/useBarcodeScanner';
 
interface BarcodeScannerViewProps {
  onDetected?: (code: string) => void;
}
 
export const BarcodeScannerView = ({ onDetected }: BarcodeScannerViewProps) => {
  const { videoRef, result } = useBarcodeScanner();
 
  useEffect(() => {
    if (result.code && onDetected) {
      onDetected(result.code);
    }
  }, [onDetected, result.code]);
 
  return (
    <Card variant="outlined">
      <CardContent>
        <Typography variant="subtitle1" gutterBottom>
          Scan Barcode
        </Typography>
        <video ref={videoRef} style={{ width: '100%', borderRadius: 8 }} />
        {result.code ? <Alert severity="success">Detected {result.code}</Alert> : null}
        {result.error ? <Alert severity="error">{result.error}</Alert> : null}
      </CardContent>
    </Card>
  );
};