Update style init to load from localStorage after mount in ComicCreationForm

This commit is contained in:
Riccardo Giorato
2026-01-13 13:17:48 +01:00
parent eb692bcca3
commit 0fcb0dae7a
+10 -8
View File
@@ -51,14 +51,8 @@ export function ComicCreationForm({
const [creditsRemaining, setCreditsRemaining] = useState<number | null>(null); const [creditsRemaining, setCreditsRemaining] = useState<number | null>(null);
const [showApiModal, setShowApiModal] = useState(false); const [showApiModal, setShowApiModal] = useState(false);
// Initialize style with saved preference or default // Initialize style with initial value, load from localStorage after mount
const [style, setStyle] = useState(() => { const [style, setStyle] = useState(initialStyle || DEFAULT_STYLE);
if (typeof window !== 'undefined') {
const saved = localStorage.getItem(STYLE_STORAGE_KEY);
return saved || initialStyle || DEFAULT_STYLE;
}
return initialStyle || DEFAULT_STYLE;
});
const fileInputRef = useRef<HTMLInputElement>(null); const fileInputRef = useRef<HTMLInputElement>(null);
const textareaRef = useRef<HTMLTextAreaElement>(null); const textareaRef = useRef<HTMLTextAreaElement>(null);
@@ -93,6 +87,14 @@ export function ComicCreationForm({
} }
}, []); // Run only on mount }, []); // Run only on mount
// Load style preference from localStorage on mount
useEffect(() => {
const saved = localStorage.getItem(STYLE_STORAGE_KEY);
if (saved) {
setStyle(saved);
}
}, []);
// Save style to localStorage and sync with parent // Save style to localStorage and sync with parent
useEffect(() => { useEffect(() => {
localStorage.setItem(STYLE_STORAGE_KEY, style); localStorage.setItem(STYLE_STORAGE_KEY, style);