All files / src/components QRCodeModal.tsx

0% Statements 0/51
0% Branches 0/1
0% Functions 0/1
0% Lines 0/51

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                                                                                                                                                     
import { useEffect } from 'react';
import { X, Download } from 'lucide-react';
import { Button } from './Button';
import { api } from '../api/client';
 
interface QRCodeModalProps {
  archiveId: number;
  archiveName: string;
  onClose: () => void;
}
 
export function QRCodeModal({ archiveId, archiveName, onClose }: QRCodeModalProps) {
  const qrCodeUrl = api.getArchiveQRCodeUrl(archiveId, 300);
 
  // Close on Escape key
  useEffect(() => {
    const handleKeyDown = (e: KeyboardEvent) => {
      if (e.key === 'Escape') onClose();
    };
    window.addEventListener('keydown', handleKeyDown);
    return () => window.removeEventListener('keydown', handleKeyDown);
  }, [onClose]);
 
  const handleDownload = () => {
    const link = document.createElement('a');
    link.href = qrCodeUrl;
    link.download = `${archiveName}_qrcode.png`;
    link.click();
  };
 
  return (
    <div
      className="fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4"
      onClick={onClose}
    >
      <div
        className="bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm"
        onClick={(e) => e.stopPropagation()}
      >
        {/* Header */}
        <div className="flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary">
          <h2 className="text-lg font-semibold text-white">QR Code</h2>
          <button
            onClick={onClose}
            className="text-bambu-gray hover:text-white transition-colors"
          >
            <X className="w-5 h-5" />
          </button>
        </div>
 
        {/* Content */}
        <div className="p-6 flex flex-col items-center">
          <p className="text-sm text-bambu-gray mb-4 text-center truncate max-w-full">
            {archiveName}
          </p>
          <div className="bg-white p-4 rounded-lg mb-4">
            <img
              src={qrCodeUrl}
              alt="QR Code"
              className="w-64 h-64"
            />
          </div>
          <p className="text-xs text-bambu-gray mb-4 text-center">
            Scan to open this archive
          </p>
          <Button onClick={handleDownload} className="w-full">
            <Download className="w-4 h-4" />
            Download QR Code
          </Button>
        </div>
      </div>
    </div>
  );
}