Restore editor history after reload
This commit is contained in:
@@ -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."
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user