import { useState, useRef } from 'react'; interface FileUploadProps { onUploadComplete: (path: string) => void; } export default function FileUpload({ onUploadComplete }: FileUploadProps) { const [isUploading, setIsUploading] = useState(false); const [dragActive, setDragActive] = useState(false); const inputRef = useRef(null); const handleFiles = async (files: FileList | null) => { if (!files || files.length === 0) return; const file = files[0]; setIsUploading(true); const formData = new FormData(); formData.append('file', file); try { const response = await fetch('/api/v1/dataset/upload', { method: 'POST', body: formData, }); if (!response.ok) { const text = await response.text(); let detail = 'Upload failed'; try { const json = JSON.parse(text); detail = json.detail || detail; } catch { detail = `Server error (${response.status}): ${text.slice(0, 100)}`; } throw new Error(detail); } const data = await response.json(); const uploadPath = `data/uploaded_datasets/${file.name.replace('.zip', '')}`; onUploadComplete(uploadPath); } catch (error: any) { console.error(error); alert(`Error: ${error.message}`); } finally { setIsUploading(false); } }; return (
{ e.preventDefault(); e.stopPropagation(); setDragActive(true); }} onDragLeave={(e) => { e.preventDefault(); e.stopPropagation(); setDragActive(false); }} onDragOver={(e) => { e.preventDefault(); e.stopPropagation(); }} onDrop={(e) => { e.preventDefault(); e.stopPropagation(); setDragActive(false); handleFiles(e.dataTransfer.files); }} > handleFiles(e.target.files)} /> {isUploading ? (

Uploading...

) : (
inputRef.current?.click()} className="cursor-pointer">

Click to upload ARKit Video / Zip

or drag and drop here

)}
); }