import { useState, useCallback, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { Upload, ArrowLeft, Trash2 } 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, selectedFilePath, spectrumLoading } = useAudioAnalysis(); const [isDragging, setIsDragging] = useState(false); const handleSelectFile = async () => { try { const filePath = await SelectFile(); if (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; } await analyzeFile(filePath); }, [analyzeFile]); useEffect(() => { OnFileDrop((x, y, paths) => { handleFileDrop(x, y, paths); }, true); return () => { OnFileDropOff(); }; }, [handleFileDrop]); const handleAnalyzeAnother = () => { clearResult(); }; return (
{isDragging ? "Drop your FLAC file here" : "Drag and drop a FLAC file here, or click the button below to select"}
Analyzing audio file...
Loading spectrum data...