From 5de3d40f1f209a1f1890a8808f6dbc7cda44965c Mon Sep 17 00:00:00 2001 From: karim Date: Sun, 18 Oct 2026 09:06:34 +0200 Subject: [PATCH] Import: Ladehinweis erscheint sofort und bleibt bis der Plan gezeichnet ist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nach dem Klick auf \"Importieren\" sah der Dialog mehrere Sekunden unverändert eingefroren aus, dann sprang die App auf den fertigen Stand. Zwei Ursachen: 1. setTimeout(0) feuert häufig VOR dem Paint — der \"Importiere …\"-Zustand wurde nie gemalt, bevor der blockierende Import startete. Jetzt zwei requestAnimationFrame: erst nach einem echten gemalten Frame beginnt die Arbeit. 2. Nach dem Einhängen blockiert der Planaufbau (Primitive + GPU-Geometrie) erneut, der Dialog war aber schon geschlossen. Neuer globaler Hinweis (busyStore + BusyOverlay): runImport startet ihn, PlanView beendet ihn nach dem ersten gezeichneten Frame des neuen Plans; Failsafe nach 120 s. --- src/App.tsx | 3 ++ src/i18n/de.ts | 1 + src/i18n/en.ts | 1 + src/plan/PlanView.tsx | 8 +++++ src/state/busyStore.ts | 53 ++++++++++++++++++++++++++++++ src/state/useProjectFileActions.ts | 4 +++ src/styles.css | 34 +++++++++++++++++++ src/ui/BusyOverlay.tsx | 15 +++++++++ src/ui/ImportDialog.tsx | 9 +++-- 9 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 src/state/busyStore.ts create mode 100644 src/ui/BusyOverlay.tsx diff --git a/src/App.tsx b/src/App.tsx index 17ecdf88..f1fbecf1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -39,6 +39,7 @@ import { sectionPlaneFromLevel } from "./plan/toSection"; import { roofBaseElevation, roofGeometry } from "./geometry/roof"; import { setDxfImportTrigger } from "./io/dxfImportHook"; import { ImportDialog } from "./ui/ImportDialog"; +import { BusyOverlay } from "./ui/BusyOverlay"; import { ExportPdfDialog } from "./ui/ExportPdfDialog"; import { ExportDxfDialog } from "./ui/ExportDxfDialog"; import { SettingsDialog } from "./ui/SettingsDialog"; @@ -3684,6 +3685,8 @@ export default function App() { /> )} + + {/* Modaler Import-Dialog (DXF/DWG) — offen, sobald eine Datei gewählt/ fallengelassen wurde. Liefert eine strukturierte Entscheidung an runImport (Ebene anlegen / Drawings anhängen / Meshes als Kontext). */} diff --git a/src/i18n/de.ts b/src/i18n/de.ts index a8f5578e..625da7fc 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -1586,6 +1586,7 @@ export const de = { "import.loading.phase.structure": "Analysiere Dateistruktur …", "import.loading.phase.parseSingle": "Parse Geometrie …", "import.loading.phase.parseParallel": "Parse Geometrie (über {n} Kerne verteilt) …", + "busy.import": "Plan wird aufgebaut …", "import.applying.heading": "Importiere ins Projekt", "import.applying.hint": "Geometrie wird ins Projekt eingehängt und Grundriss/3D neu aufgebaut … Bei sehr vielen Elementen kann das einen Moment dauern.", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 9336e833..26ef8b36 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -1574,6 +1574,7 @@ export const en: Record = { "import.loading.phase.structure": "Analyzing file structure …", "import.loading.phase.parseSingle": "Parsing geometry …", "import.loading.phase.parseParallel": "Parsing geometry (spread across {n} cores) …", + "busy.import": "Building plan …", "import.applying.heading": "Importing into project", "import.applying.hint": "Attaching geometry to the project and rebuilding plan/3D … this can take a moment for very many elements.", diff --git a/src/plan/PlanView.tsx b/src/plan/PlanView.tsx index f3d64389..b9e73575 100644 --- a/src/plan/PlanView.tsx +++ b/src/plan/PlanView.tsx @@ -58,6 +58,7 @@ import { PlanRulers } from "./planView/PlanRulers"; import { PlanGrid } from "./planView/PlanGrid"; import { expandRegion, indexedInRegion, regionContains, type Bounds } from "./planView/cullPrimitives"; import { buildSegmentIndex, nearestSegment, pointSegDist } from "./planView/segmentIndex"; +import { endBusyAfterPaint } from "../state/busyStore"; import { createCursorStore, useCursorValue, type CursorStore } from "../state/cursorStore"; /** @@ -870,6 +871,13 @@ export const PlanView = forwardRef( // eslint-disable-next-line react-hooks/exhaustive-deps }, [useGpuRenderer, plan, updateGeometry, renderGl]); + // Import-Hinweis (busyStore) beenden, sobald der neue Plan aufgebaut UND + // gezeichnet ist — deklariert NACH dem Geometrie-Effekt oben, läuft also + // danach; das Beenden wartet zusätzlich auf den nächsten gemalten Frame. + useEffect(() => { + endBusyAfterPaint(); + }, [plan]); + // GL bei jeder Ausschnittsänderung (Pan/Zoom) neu zeichnen. Normalfall: NUR // Matrix-Uniform (keine Re-Tessellierung → flüssig). Ausnahme: hat der Zoom // einen neuen LOD-Bucket erreicht, werden die Bögen einmalig mit dem neuen diff --git a/src/state/busyStore.ts b/src/state/busyStore.ts new file mode 100644 index 00000000..70b5229d --- /dev/null +++ b/src/state/busyStore.ts @@ -0,0 +1,53 @@ +// Globaler "Bitte warten"-Hinweis für lange, den Haupt-Thread blockierende +// Schritte (Import grosser Dateien). Ausserhalb von React-State, weil der +// Aufrufer (runImport) und der Beender (PlanView, nach dem ersten gezeichneten +// Frame) in völlig verschiedenen Teilbäumen sitzen. +// +// Ablauf Import: Dialog zeigt "Importiere …" (gemalt, BEVOR die Arbeit startet) +// → runImport ruft beginBusy → Dialog schliesst, Plan wird aufgebaut (blockiert) +// → PlanView ruft nach dem Zeichnen endBusy. Dazwischen steht der Hinweis, statt +// dass die App scheinbar eingefroren ist. + +import { useSyncExternalStore } from "react"; + +let current: string | null = null; +let failsafe: ReturnType | null = null; +const listeners = new Set<() => void>(); + +function emit(): void { + for (const l of listeners) l(); +} + +/** Zeigt `label`. Verschwindet spätestens nach `maxMs` von selbst (nie hängen bleiben). */ +export function beginBusy(label: string, maxMs = 120_000): void { + current = label; + if (failsafe !== null) clearTimeout(failsafe); + failsafe = setTimeout(endBusy, maxMs); + emit(); +} + +export function endBusy(): void { + if (failsafe !== null) { + clearTimeout(failsafe); + failsafe = null; + } + if (current === null) return; + current = null; + emit(); +} + +/** Wie {@link endBusy}, aber erst NACH dem nächsten gemalten Frame. */ +export function endBusyAfterPaint(): void { + if (current === null) return; + requestAnimationFrame(() => requestAnimationFrame(endBusy)); +} + +export function useBusy(): string | null { + return useSyncExternalStore( + (l) => { + listeners.add(l); + return () => listeners.delete(l); + }, + () => current, + ); +} diff --git a/src/state/useProjectFileActions.ts b/src/state/useProjectFileActions.ts index bb99c3d6..f1e28272 100644 --- a/src/state/useProjectFileActions.ts +++ b/src/state/useProjectFileActions.ts @@ -11,6 +11,7 @@ import type { RefObject } from "react"; import { t } from "../i18n"; import type { DxfImportResult } from "../io/dxfParser"; import { parseDxfAsync } from "../io/dxfParserAsync"; +import { beginBusy } from "./busyStore"; import { buildDrawings } from "../ui/ImportDialog"; import { distinctImportLayers, planImportCategories } from "../io/dxfToDrawings"; import type { ImportDecision } from "../ui/ImportDialog"; @@ -490,6 +491,9 @@ export function useProjectFileActions( // 2D-Konturen als Drawing2D anhängen, optional die Meshes als Kontext // übernehmen. Reihenfolge: erst Ebene (echte ID), dann Drawings/Kontext. const runImport = (decision: ImportDecision) => { + // Hinweis bleibt, bis PlanView den neuen Plan gezeichnet hat (endBusyAfterPaint): + // der Aufbau nach dem Einhängen blockiert noch einmal mehrere Sekunden. + beginBusy(t("busy.import")); const levelId = decision.target.kind === "new" ? addDrawingLevel(decision.target.name) diff --git a/src/styles.css b/src/styles.css index a66d284b..c555c6bf 100644 --- a/src/styles.css +++ b/src/styles.css @@ -7943,3 +7943,37 @@ body { background: #ece8e2; color: #1a1a18; } + +/* "Bitte warten" während lange blockierender Schritte (Import grosser Dateien). */ +.busy-overlay { + position: fixed; + inset: 0; + z-index: 1200; + background: var(--overlay); + display: flex; + align-items: center; + justify-content: center; + cursor: progress; +} +.busy-card { + display: flex; + align-items: center; + gap: 12px; + padding: 16px 22px; + background: var(--panel); + border: 1px solid var(--border); + border-radius: 10px; + box-shadow: var(--shadow-3); + color: var(--text); +} +.busy-spinner { + width: 18px; + height: 18px; + border: 2px solid var(--border); + border-top-color: var(--accent, currentColor); + border-radius: 50%; + animation: busy-spin 0.8s linear infinite; +} +@keyframes busy-spin { + to { transform: rotate(360deg); } +} diff --git a/src/ui/BusyOverlay.tsx b/src/ui/BusyOverlay.tsx new file mode 100644 index 00000000..f5eef633 --- /dev/null +++ b/src/ui/BusyOverlay.tsx @@ -0,0 +1,15 @@ +import { useBusy } from "../state/busyStore"; + +/** Vollflächiger "Bitte warten"-Hinweis, solange `busyStore` ein Label hält. */ +export function BusyOverlay() { + const label = useBusy(); + if (!label) return null; + return ( +
+
+ +
+ ); +} diff --git a/src/ui/ImportDialog.tsx b/src/ui/ImportDialog.tsx index 1319ecd4..bb14b4a2 100644 --- a/src/ui/ImportDialog.tsx +++ b/src/ui/ImportDialog.tsx @@ -160,7 +160,7 @@ export function ImportDialog({ // Sekunden dauernden — Drawings ins Projekt einhängen + Plan/3D neu bauen) // `onImport`: zeigt einen Ladehinweis, STATT sofort zu blockieren (Nutzer- // Report 2026-10-09: nach Klick auf „Importieren" keine Rückmeldung, nicht - // unterscheidbar von einem Hänger). `setTimeout` statt direktem Aufruf gibt + // unterscheidbar von einem Hänger). Zwei `requestAnimationFrame` statt direktem Aufruf geben // dem Browser einen Frame, um diesen Zustand VOR dem schweren synchronen // Teil zu malen — sonst würde React den State-Update-Commit gar nicht mehr // vor dem Block zum Zug kommen lassen. @@ -176,7 +176,12 @@ export function ImportDialog({ ? ({ kind: "existing", levelId: existingLevelId } as const) : ({ kind: "new", name: newName } as const); setApplying(true); - setTimeout(() => onImport({ target, categoryMode, importMeshes, placement, parsed }), 0); + // Zwei Frames warten: erst dann ist der "Importiere …"-Zustand tatsächlich + // GEMALT. Ein setTimeout(0) feuert oft vor dem Paint — der Dialog sah dann + // bis zum Ende des (blockierenden) Imports unverändert eingefroren aus. + requestAnimationFrame(() => + requestAnimationFrame(() => onImport({ target, categoryMode, importMeshes, placement, parsed })), + ); }; return (