import { useState, useCallback, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { Upload, ArrowLeft } 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"; interface AudioAnalysisPageProps { onBack?: () => void; } export function AudioAnalysisPage({ onBack }: AudioAnalysisPageProps) { 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]; 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] ); useEffect(() => { OnFileDrop((x, y, paths) => { handleFileDrop(x, y, paths); }, true); return () => { OnFileDropOff(); }; }, [handleFileDrop]); const handleAnalyzeAnother = () => { clearResult(); setSelectedFilePath(""); }; return (
{/* Header */}
{onBack && ( )}

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} >

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

)} {/* Loading State */} {analyzing && !result && (

Analyzing audio file...

)} {/* Analysis Results */} {result && (
{/* File Info with Analyze Another Button */}

{selectedFilePath}

{/* Spectrum Visualization */} {/* Detailed Analysis */}
)}
); }