mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
fix: info page editor — locale switch no longer resets user edits
Split the form population effect into two: 1. Form fields (slug, icon, active, titles, contents) — populated once when pageData loads, never re-run on locale switch 2. Editor content — set once when editor instance is ready Previously activeLocale was in the deps array, causing every tab switch to overwrite all in-memory edits with original server data.
This commit is contained in:
@@ -411,10 +411,11 @@ export default function AdminInfoPageEditor() {
|
|||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Populate form when page data loads
|
// Populate form when page data loads (once only — not on locale switch)
|
||||||
const editorPopulated = useRef(false);
|
const editorPopulated = useRef(false);
|
||||||
|
const formPopulated = useRef(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!pageData) return;
|
if (!pageData || formPopulated.current) return;
|
||||||
setSlug(pageData.slug);
|
setSlug(pageData.slug);
|
||||||
setSlugManuallyEdited(true);
|
setSlugManuallyEdited(true);
|
||||||
setIcon(pageData.icon ?? '');
|
setIcon(pageData.icon ?? '');
|
||||||
@@ -422,11 +423,16 @@ export default function AdminInfoPageEditor() {
|
|||||||
setSortOrder(pageData.sort_order);
|
setSortOrder(pageData.sort_order);
|
||||||
setTitles(pageData.title);
|
setTitles(pageData.title);
|
||||||
setContents(pageData.content);
|
setContents(pageData.content);
|
||||||
if (editor && pageData.content[activeLocale] && !editorPopulated.current) {
|
formPopulated.current = true;
|
||||||
editor.commands.setContent(pageData.content[activeLocale] ?? '');
|
}, [pageData]);
|
||||||
editorPopulated.current = true;
|
|
||||||
}
|
// Set editor content once when editor is ready
|
||||||
}, [pageData, editor, activeLocale]);
|
useEffect(() => {
|
||||||
|
if (!pageData || !editor || editorPopulated.current) return;
|
||||||
|
const initialContent = pageData.content[activeLocale] ?? pageData.content['ru'] ?? '';
|
||||||
|
editor.commands.setContent(initialContent);
|
||||||
|
editorPopulated.current = true;
|
||||||
|
}, [pageData, editor]); // activeLocale intentionally omitted
|
||||||
|
|
||||||
// Auto-generate slug from Russian title
|
// Auto-generate slug from Russian title
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user