From 56c4067703ced833063630d7b6ebb7ea9387edcf Mon Sep 17 00:00:00 2001 From: webadderall <131426131+webadderall@users.noreply.github.com> Date: Sat, 28 Mar 2026 22:36:04 +1100 Subject: [PATCH] fix(editor): remount preview after project saves --- src/components/video-editor/VideoEditor.tsx | 98 ++++++++++++--------- 1 file changed, 54 insertions(+), 44 deletions(-) diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsx index dc11eec5..3c4d329b 100644 --- a/src/components/video-editor/VideoEditor.tsx +++ b/src/components/video-editor/VideoEditor.tsx @@ -642,6 +642,10 @@ export default function VideoEditor() { })); }, []); + const remountPreview = useCallback(() => { + setPreviewVersion((version) => version + 1); + }, []); + useEffect(() => { return () => { exporterRef.current?.cancel(); @@ -1576,53 +1580,57 @@ export default function VideoEditor() { return false; } - const projectData = - currentProjectSnapshot?.videoPath === currentSourcePath - ? currentProjectSnapshot - : createProjectData(currentSourcePath, currentPersistedEditorState); + try { + const projectData = + currentProjectSnapshot?.videoPath === currentSourcePath + ? currentProjectSnapshot + : createProjectData(currentSourcePath, currentPersistedEditorState); - const fileNameBase = - currentSourcePath - .split(/[\\/]/) - .pop() - ?.replace(/\.[^.]+$/, "") || `project-${Date.now()}`; - let targetProjectPath = forceSaveAs ? undefined : (currentProjectPath ?? undefined); + const fileNameBase = + currentSourcePath + .split(/[\\/]/) + .pop() + ?.replace(/\.[^.]+$/, "") || `project-${Date.now()}`; + let targetProjectPath = forceSaveAs ? undefined : (currentProjectPath ?? undefined); - if (!forceSaveAs && !targetProjectPath) { - const activeProjectResult = await window.electronAPI.loadCurrentProjectFile(); - if (activeProjectResult.success && activeProjectResult.path) { - targetProjectPath = activeProjectResult.path; - setCurrentProjectPath(activeProjectResult.path); + if (!forceSaveAs && !targetProjectPath) { + const activeProjectResult = await window.electronAPI.loadCurrentProjectFile(); + if (activeProjectResult.success && activeProjectResult.path) { + targetProjectPath = activeProjectResult.path; + setCurrentProjectPath(activeProjectResult.path); + } } + + const thumbnailDataUrl = await captureProjectThumbnail(); + + const result = await window.electronAPI.saveProjectFile( + projectData, + fileNameBase, + targetProjectPath, + thumbnailDataUrl, + ); + + if (result.canceled) { + toast.info("Project save canceled"); + return false; + } + + if (!result.success) { + toast.error(result.message || "Failed to save project"); + return false; + } + + if (result.path) { + setCurrentProjectPath(result.path); + } + setLastSavedSnapshot(cloneStructured(projectData)); + await refreshProjectLibrary(); + + toast.success(`Project saved to ${result.path}`); + return true; + } finally { + remountPreview(); } - - const thumbnailDataUrl = await captureProjectThumbnail(); - - const result = await window.electronAPI.saveProjectFile( - projectData, - fileNameBase, - targetProjectPath, - thumbnailDataUrl, - ); - - if (result.canceled) { - toast.info("Project save canceled"); - return false; - } - - if (!result.success) { - toast.error(result.message || "Failed to save project"); - return false; - } - - if (result.path) { - setCurrentProjectPath(result.path); - } - setLastSavedSnapshot(cloneStructured(projectData)); - await refreshProjectLibrary(); - - toast.success(`Project saved to ${result.path}`); - return true; }, [ captureProjectThumbnail, @@ -1631,6 +1639,7 @@ export default function VideoEditor() { currentProjectSnapshot, currentPersistedEditorState, refreshProjectLibrary, + remountPreview, ], ); @@ -2677,7 +2686,7 @@ export default function VideoEditor() { exporterRef.current = null; setShowExportDropdown(keepExportDialogOpen); setExportProgress(null); - setPreviewVersion((version) => version + 1); + remountPreview(); } }, [ @@ -2720,6 +2729,7 @@ export default function VideoEditor() { effectiveZoomRegions, ensureSupportedMp4SourceDimensions, markExportAsSaving, + remountPreview, showExportSuccessToast, ], );