import { useState, useRef } from 'react'; interface JsonUploadModalProps { isOpen: boolean; onClose: () => void; // has to be any as this is a dynamic trackerm with dynamic score formats // eslint-disable-next-line @typescript-eslint/no-explicit-any onUpload: (data: any) => void; game: string; } const JsonUploadModal = ({ isOpen, onClose, onUpload, game }: JsonUploadModalProps) => { const [file, setFile] = useState(null); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const fileInputRef = useRef(null); if (!isOpen) return null; const handleFileChange = (e: React.ChangeEvent) => { const selectedFile = e.target.files?.[0]; setError(''); if (selectedFile) { if (!selectedFile.name.endsWith('.json')) { setError('Please select a JSON file'); return; } setFile(selectedFile); } }; const handleUpload = async () => { if (!file) { setError('Please select a file to upload'); return; } setIsLoading(true); setError(''); try { const text = await file.text(); const data = JSON.parse(text); onUpload(data); setFile(null); if (fileInputRef.current) { fileInputRef.current.value = ''; } onClose(); } catch (err) { if (err instanceof SyntaxError) { setError('Invalid JSON file format'); } else { setError('Failed to process file. Please try again.'); } } finally { setIsLoading(false); } }; const handleClose = () => { setFile(null); setError(''); if (fileInputRef.current) { fileInputRef.current.value = ''; } onClose(); }; return (
{/* Backdrop */}
{/* Modal */}
{/* Header */}

Import {game} Data

Upload your game data in JSON format

{/* File Upload Area */}
{/* Error Message */} {error && (

{error}

)} {/* Actions */}
); }; export default JsonUploadModal;