diff --git a/admin-lehrer/components/grid-editor/useGridEditor.ts b/admin-lehrer/components/grid-editor/useGridEditor.ts index 83e5c10..9936ddd 100644 --- a/admin-lehrer/components/grid-editor/useGridEditor.ts +++ b/admin-lehrer/components/grid-editor/useGridEditor.ts @@ -1,4 +1,4 @@ -import { useCallback, useRef, useState } from 'react' +import { useCallback, useEffect, useRef, useState } from 'react' import type { StructuredGrid, GridZone, LayoutDividers } from './types' const KLAUSUR_API = '/klausur-api' @@ -101,6 +101,19 @@ export function useGridEditor(sessionId: string | null) { } }, [sessionId, buildGrid]) + // Auto-rebuild when IPA or syllable mode changes (skip initial mount) + const initialLoadDone = useRef(false) + useEffect(() => { + if (!initialLoadDone.current) { + // Mark as initialized once the first grid is loaded + if (grid) initialLoadDone.current = true + return + } + // Mode changed after initial load — rebuild + buildGrid() + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [ipaMode, syllableMode]) + // ------------------------------------------------------------------ // Save // ------------------------------------------------------------------