diff --git a/src/components/video-editor/ExportDialog.tsx b/src/components/video-editor/ExportDialog.tsx index b36020c6..bd3b99d9 100644 --- a/src/components/video-editor/ExportDialog.tsx +++ b/src/components/video-editor/ExportDialog.tsx @@ -1,6 +1,5 @@ import { Download, Loader2, X } from "lucide-react"; import { useEffect, useState } from "react"; -import { toast } from "sonner"; // Add this import import { Button } from "@/components/ui/button"; import type { ExportProgress } from "@/lib/exporter"; @@ -13,6 +12,7 @@ interface ExportDialogProps { onCancel?: () => void; exportFormat?: "mp4" | "gif"; exportedFilePath?: string; + onShowInFolder?: () => void; } export function ExportDialog({ @@ -23,7 +23,8 @@ export function ExportDialog({ error, onCancel, exportFormat = "mp4", - exportedFilePath, // Add this line + exportedFilePath, + onShowInFolder, }: ExportDialogProps) { const [showSuccess, setShowSuccess] = useState(false); @@ -85,23 +86,6 @@ export function ExportDialog({ return `Exporting ${formatLabel}`; }; - const handleClickShowInFolder = async () => { - if (exportedFilePath) { - try { - const result = await window.electronAPI.revealInFolder(exportedFilePath); - if (!result.success) { - const errorMessage = result.error || result.message || "Failed to reveal item in folder."; - console.error("Failed to reveal in folder:", errorMessage); - toast.error(errorMessage); - } - } catch (err) { - const errorMessage = String(err); - console.error("Error calling revealInFolder IPC:", errorMessage); - toast.error(`Error revealing in folder: ${errorMessage}`); - } - } - }; - return ( <>
Show in Folder diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsx index 829cde5b..1b6de7e4 100644 --- a/src/components/video-editor/VideoEditor.tsx +++ b/src/components/video-editor/VideoEditor.tsx @@ -103,6 +103,7 @@ export default function VideoEditor() { const [gifFrameRate, setGifFrameRate] = useState(15); const [gifLoop, setGifLoop] = useState(true); const [gifSizePreset, setGifSizePreset] = useState("medium"); + const [exportedFilePath, setExportedFilePath] = useState(null); const [lastSavedSnapshot, setLastSavedSnapshot] = useState(null); const videoPlaybackRef = useRef(null); @@ -929,6 +930,37 @@ export default function VideoEditor() { } }, [selectedSpeedId, speedRegions]); + const handleShowExportedFile = useCallback(async (filePath: string) => { + try { + const result = await window.electronAPI.revealInFolder(filePath); + if (!result.success) { + const errorMessage = result.error || result.message || "Failed to reveal item in folder."; + console.error("Failed to reveal in folder:", errorMessage); + toast.error(errorMessage); + } + } catch (error) { + const errorMessage = String(error); + console.error("Error calling revealInFolder IPC:", errorMessage); + toast.error(`Error revealing in folder: ${errorMessage}`); + } + }, []); + + const handleExportSaved = useCallback( + (formatLabel: "GIF" | "Video", filePath: string) => { + setExportedFilePath(filePath); + toast.success(`${formatLabel} exported successfully`, { + description: filePath, + action: { + label: "Show in Folder", + onClick: () => { + void handleShowExportedFile(filePath); + }, + }, + }); + }, + [handleShowExportedFile], + ); + const handleExport = useCallback( async (settings: ExportSettings) => { if (!videoPath) { @@ -945,6 +977,7 @@ export default function VideoEditor() { setIsExporting(true); setExportProgress(null); setExportError(null); + setExportedFilePath(null); try { const wasPlaying = isPlaying; @@ -1008,7 +1041,7 @@ export default function VideoEditor() { if (saveResult.canceled) { toast.info("Export canceled"); } else if (saveResult.success) { - toast.success(`GIF exported successfully to ${saveResult.path}`); + handleExportSaved("GIF", saveResult.path); } else { setExportError(saveResult.message || "Failed to save GIF"); toast.error(saveResult.message || "Failed to save GIF"); @@ -1135,7 +1168,7 @@ export default function VideoEditor() { if (saveResult.canceled) { toast.info("Export canceled"); } else if (saveResult.success) { - toast.success(`Video exported successfully to ${saveResult.path}`); + handleExportSaved("Video", saveResult.path); } else { setExportError(saveResult.message || "Failed to save video"); toast.error(saveResult.message || "Failed to save video"); @@ -1180,6 +1213,7 @@ export default function VideoEditor() { isPlaying, aspectRatio, exportQuality, + handleExportSaved, ], ); @@ -1222,6 +1256,7 @@ export default function VideoEditor() { setShowExportDialog(true); setExportError(null); + setExportedFilePath(null); // Start export immediately handleExport(settings); @@ -1235,6 +1270,7 @@ export default function VideoEditor() { setIsExporting(false); setExportProgress(null); setExportError(null); + setExportedFilePath(null); } }, []); @@ -1473,6 +1509,10 @@ export default function VideoEditor() { error={exportError} onCancel={handleCancelExport} exportFormat={exportFormat} + exportedFilePath={exportedFilePath || undefined} + onShowInFolder={ + exportedFilePath ? () => void handleShowExportedFile(exportedFilePath) : undefined + } />
);