Restore editor history after reload

This commit is contained in:
2026-07-25 21:45:58 +02:00
parent c45afd0981
commit 4b47bc2bcc
10 changed files with 275 additions and 423 deletions
@@ -0,0 +1,27 @@
import type {
CircuitTreeResponseDto,
ProjectHistoryStateDto,
} from "../types";
export interface CircuitEditorSnapshot {
tree: CircuitTreeResponseDto;
history: ProjectHistoryStateDto;
}
export async function loadCircuitEditorSnapshot(
readTree: () => Promise<CircuitTreeResponseDto>,
readHistory: () => Promise<ProjectHistoryStateDto>,
maxAttempts = 3
): Promise<CircuitEditorSnapshot> {
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
const tree = await readTree();
const history = await readHistory();
if (tree.currentRevision === history.currentRevision) {
return { tree, history };
}
}
throw new Error(
"Der Projektstand hat sich während des Ladens geändert. Bitte erneut versuchen."
);
}