From 7d746196d2c26e4e6f742177fa3e6861940b50b3 Mon Sep 17 00:00:00 2001 From: JasonOA888 Date: Sat, 4 Apr 2026 23:27:56 +0800 Subject: [PATCH] fix: persist user settings across sessions (closes #306) Load saved preferences (padding, aspect ratio, export quality, export format) on mount and auto-save whenever these settings change. Uses the existing userPreferences.ts utility with a ref guard to prevent overwriting saved prefs with defaults before the initial load completes. --- src/components/video-editor/VideoEditor.tsx | 26 ++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsx index e2e34f1..6d7c5c5 100644 --- a/src/components/video-editor/VideoEditor.tsx +++ b/src/components/video-editor/VideoEditor.tsx @@ -21,8 +21,8 @@ import { VideoExporter, } from "@/lib/exporter"; import type { ProjectMedia } from "@/lib/recordingSession"; -import { loadUserPreferences, saveUserPreferences } from "@/lib/userPreferences"; import { matchesShortcut } from "@/lib/shortcuts"; +import { loadUserPreferences, saveUserPreferences } from "@/lib/userPreferences"; import { getAspectRatioValue, getNativeAspectRatioValue, @@ -360,6 +360,30 @@ export default function VideoEditor() { loadInitialData(); }, [applyLoadedProject]); + // Track whether user preferences have been loaded to avoid + // overwriting saved prefs with defaults on the first render + const prefsLoadedRef = useRef(false); + + // Load persisted user preferences on mount + useEffect(() => { + const prefs = loadUserPreferences(); + updateState({ + padding: prefs.padding, + aspectRatio: prefs.aspectRatio, + }); + setExportQuality(prefs.exportQuality); + setExportFormat(prefs.exportFormat); + prefsLoadedRef.current = true; + // We intentionally only want this to run once on mount + // biome-ignore lint/correctness/useExhaustiveDependencies: mount-only effect + }, []); + + // Auto-save user preferences when settings change + useEffect(() => { + if (!prefsLoadedRef.current) return; + saveUserPreferences({ padding, aspectRatio, exportQuality, exportFormat }); + }, [padding, aspectRatio, exportQuality, exportFormat]); + const saveProject = useCallback( async (forceSaveAs: boolean) => { if (!videoPath) {