import { useState, useRef } from "react"; import { Button } from "@/components/ui/button"; import { Progress } from "@/components/ui/progress"; import { AlertCircle, Upload, CheckCircle2 } from "lucide-react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; interface TrackUploadModalProps { open: boolean; onOpenChange: (open: boolean) => void; onFileSelected: (file: File) => void; isLoading?: boolean; } const MAX_FILE_SIZE = 50 * 1024 * 1024; // 50MB const ALLOWED_TYPES = ["audio/mpeg", "audio/wav", "audio/mp3"]; export default function TrackUploadModal({ open, onOpenChange, onFileSelected, isLoading, }: TrackUploadModalProps) { const [file, setFile] = useState(null); const [error, setError] = useState(null); const [uploadProgress, setUploadProgress] = useState(0); const fileInputRef = useRef(null); const handleFileChange = (e: React.ChangeEvent) => { const selectedFile = e.target.files?.[0]; if (!selectedFile) return; setError(null); setFile(null); if (!ALLOWED_TYPES.includes(selectedFile.type)) { setError("Please upload an MP3 or WAV file"); return; } if (selectedFile.size > MAX_FILE_SIZE) { setError("File is too large. Maximum size is 50MB"); return; } setFile(selectedFile); }; const handleUpload = () => { if (!file) return; onFileSelected(file); }; const handleReset = () => { setFile(null); setError(null); setUploadProgress(0); if (fileInputRef.current) { fileInputRef.current.value = ""; } }; const handleClose = () => { if (!isLoading) { handleReset(); onOpenChange(false); } }; return ( Upload Audio Track Upload your music or sound effects (MP3 or WAV, up to 50MB)
{!file ? (
fileInputRef.current?.click()} >

Click to upload or drag and drop

MP3 or WAV • Up to 50MB

) : (

{file.name}

{(file.size / 1024 / 1024).toFixed(2)} MB

{isLoading && (
Uploading... {uploadProgress}%
)}
)} {error && (

{error}

)}
{file && !isLoading && ( <> )} {!file && ( )}
); }