Import: Ladehinweis erscheint sofort und bleibt bis der Plan gezeichnet ist
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.
This commit is contained in:
1 parent
996fe61c8a
commit
5de3d40f1f
9 files changed
+126
-2
No files matched your search
@@ -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() {
|
||||
/>
|
||||
)}
|
||||
|
||||
<BusyOverlay />
|
||||
|
||||
{/* 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). */}
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -1574,6 +1574,7 @@ export const en: Record<TranslationKey, string> = {
|
||||
"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.",
|
||||
|
||||
@@ -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<PlanViewHandle, PlanViewProps>(
|
||||
// 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
|
||||
|
||||
@@ -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<typeof setTimeout> | 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,
|
||||
);
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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); }
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="busy-overlay" role="status" aria-live="polite">
|
||||
<div className="busy-card">
|
||||
<div className="busy-spinner" aria-hidden="true" />
|
||||
<div className="busy-label">{label}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
|
||||
Reference in new issue
Block a user