Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions src/components/video-editor/ExportDialog.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -13,6 +12,7 @@ interface ExportDialogProps {
onCancel?: () => void;
exportFormat?: "mp4" | "gif";
exportedFilePath?: string;
onShowInFolder?: () => void;
}

export function ExportDialog({
Expand All @@ -23,7 +23,8 @@ export function ExportDialog({
error,
onCancel,
exportFormat = "mp4",
exportedFilePath, // Add this line
exportedFilePath,
onShowInFolder,
}: ExportDialogProps) {
const [showSuccess, setShowSuccess] = useState(false);

Expand Down Expand Up @@ -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 (
<>
<div
Expand All @@ -124,7 +108,7 @@ export function ExportDialog({
{exportedFilePath && (
<Button
variant="secondary"
onClick={handleClickShowInFolder}
onClick={onShowInFolder}
className="mt-2 w-fit px-3 py-1 text-sm rounded-md bg-white/10 hover:bg-white/20 text-slate-200"
>
Show in Folder
Expand Down
44 changes: 42 additions & 2 deletions src/components/video-editor/VideoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
const [gifFrameRate, setGifFrameRate] = useState<GifFrameRate>(15);
const [gifLoop, setGifLoop] = useState(true);
const [gifSizePreset, setGifSizePreset] = useState<GifSizePreset>("medium");
const [exportedFilePath, setExportedFilePath] = useState<string | null>(null);
const [lastSavedSnapshot, setLastSavedSnapshot] = useState<string | null>(null);

const videoPlaybackRef = useRef<VideoPlaybackRef>(null);
Expand Down Expand Up @@ -929,6 +930,37 @@
}
}, [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) {
Expand All @@ -945,6 +977,7 @@
setIsExporting(true);
setExportProgress(null);
setExportError(null);
setExportedFilePath(null);

try {
const wasPlaying = isPlaying;
Expand Down Expand Up @@ -1008,7 +1041,7 @@
if (saveResult.canceled) {
toast.info("Export canceled");
} else if (saveResult.success) {
toast.success(`GIF exported successfully to ${saveResult.path}`);
handleExportSaved("GIF", saveResult.path);

Check failure on line 1044 in src/components/video-editor/VideoEditor.tsx

View workflow job for this annotation

GitHub Actions / Type Check

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

Check failure on line 1044 in src/components/video-editor/VideoEditor.tsx

View workflow job for this annotation

GitHub Actions / E2E Tests

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
} else {
setExportError(saveResult.message || "Failed to save GIF");
toast.error(saveResult.message || "Failed to save GIF");
Expand Down Expand Up @@ -1135,7 +1168,7 @@
if (saveResult.canceled) {
toast.info("Export canceled");
} else if (saveResult.success) {
toast.success(`Video exported successfully to ${saveResult.path}`);
handleExportSaved("Video", saveResult.path);

Check failure on line 1171 in src/components/video-editor/VideoEditor.tsx

View workflow job for this annotation

GitHub Actions / Type Check

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

Check failure on line 1171 in src/components/video-editor/VideoEditor.tsx

View workflow job for this annotation

GitHub Actions / E2E Tests

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
} else {
setExportError(saveResult.message || "Failed to save video");
toast.error(saveResult.message || "Failed to save video");
Expand Down Expand Up @@ -1180,6 +1213,7 @@
isPlaying,
aspectRatio,
exportQuality,
handleExportSaved,
],
);

Expand Down Expand Up @@ -1222,6 +1256,7 @@

setShowExportDialog(true);
setExportError(null);
setExportedFilePath(null);

// Start export immediately
handleExport(settings);
Expand All @@ -1235,6 +1270,7 @@
setIsExporting(false);
setExportProgress(null);
setExportError(null);
setExportedFilePath(null);
}
}, []);

Expand Down Expand Up @@ -1473,6 +1509,10 @@
error={exportError}
onCancel={handleCancelExport}
exportFormat={exportFormat}
exportedFilePath={exportedFilePath || undefined}
onShowInFolder={
exportedFilePath ? () => void handleShowExportedFile(exportedFilePath) : undefined
}
/>
</div>
);
Expand Down
Loading