import { useState, useCallback } from "react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; import { Activity, Upload, X } from "lucide-react"; import { AudioAnalysis } from "@/components/AudioAnalysis"; import { SpectrumVisualization } from "@/components/SpectrumVisualization"; import { useAudioAnalysis } from "@/hooks/useAudioAnalysis"; import { SelectFile } from "../../wailsjs/go/main/App"; import { toastWithSound as toast } from "@/lib/toast-with-sound"; import { OnFileDrop, OnFileDropOff } from "../../wailsjs/runtime/runtime"; import { useEffect } from "react"; export function AudioAnalysisDialog() { const [open, setOpen] = useState(false); const { analyzing, result, analyzeFile, clearResult } = useAudioAnalysis(); const [selectedFilePath, setSelectedFilePath] = useState(""); const [isDragging, setIsDragging] = useState(false); const handleSelectFile = async () => { try { const filePath = await SelectFile(); if (filePath) { setSelectedFilePath(filePath); await analyzeFile(filePath); } } catch (err) { toast.error("File Selection Failed", { description: err instanceof Error ? err.message : "Failed to select file", }); } }; const handleFileDrop = useCallback(async (_x: number, _y: number, paths: string[]) => { setIsDragging(false); if (paths.length === 0) return; const filePath = paths[0]; // Check if it's a FLAC file if (!filePath.toLowerCase().endsWith('.flac')) { toast.error("Invalid File Type", { description: "Please drop a FLAC file for analysis", }); return; } setSelectedFilePath(filePath); await analyzeFile(filePath); }, [analyzeFile]); // Register drag and drop handlers when dialog is open useEffect(() => { if (open) { OnFileDrop((x, y, paths) => { handleFileDrop(x, y, paths); }, true); return () => { OnFileDropOff(); }; } }, [open, handleFileDrop]); const handleClose = () => { setOpen(false); setTimeout(() => { clearResult(); setSelectedFilePath(""); }, 200); }; return ( { if (!isOpen) { handleClose(); } else { setOpen(true); } }}>

Audio Quality Analyzer

Audio Quality Analyzer
{/* File Selection */} {!result && !analyzing && (
{ e.preventDefault(); setIsDragging(true); }} onDragLeave={(e) => { e.preventDefault(); setIsDragging(false); }} onDrop={(e) => { e.preventDefault(); setIsDragging(false); }} style={{ "--wails-drop-target": "drop" } as React.CSSProperties} >

Analyze FLAC Audio Quality

{isDragging ? "Drop your FLAC file here" : "Drag and drop a FLAC file here, or click the button below to select"}

)} {/* Analysis Results */} {result && (
{/* File Info */}

Analyzing file:

{selectedFilePath}

{/* Spectrum Visualization */} {/* Detailed Analysis */} {/* Actions */}
)} {/* Loading State */} {analyzing && !result && (

Analyzing audio file...

)}
); }